If I use Google Place Autocomplete for "Alpha Loft Elm" I get an address that includes only level 1 (state) in the administrative areas. But if I autocomplete for the same place using the returned formatted_address, "844 Elm St, Manchester, NH 03101, United States", I get level 2 (county) as well, with a different place-id.
I see the same behavior for other places as well. I see the same behavior from the Place Details API, when I give it the place-id returned in each case.
I need the county, and need to support autocomplete by place name.
The only workaround I've found for this is to use Place Search (textsearch) on the returned formatted_address, then use Place Details on the placeId returned for the address to get the county.
Is there a better approach?
(Also posted as a bug report on gmaps-api-issues.)
So far I am not aware of any other solution then after using Autocomplete to get the accurate address and place_id to use something like the following code to retrieve the "political" structure behind that address.
if (place.place_id) {
var service = new google.maps.places.PlacesService(map);
service.getDetails({placeId: place.place_id}, function (PlaceResult, PlacesServiceStatus) {
console.log(PlaceResult);
});
}
Related
I am new to "Here" and I am using Here SDK Flutter 4.3.3.0. I want to fetch/search for places and get the Place's Photos/Image and or Place's Logo if the place is a business/company.
The place images place.details.internalimages are always empty when I search for any place. I tried for different countries like "Chipotle" a restaurant near Las Vegas, a restaurant in Canda, and a Shopping mall in India. All of these return 0 (zero) images. Does, Here API support to get places photos like Google Places or TomTom API?
Looks like this API has a method to get WebImage List but does not contain any data at all. Please advise, If I need to use any other method to get Place's photos.
Another question is, is there a way to get a company logo, if the place I am searching for is a business/company like Restaurant, Store, etc.
Below is the code, I use in my Flutter application. Note, I am able to get other field values like title, address, etc.
TextQuery textQuery = TextQuery.withAreaCenterInCountries('some partial place name', geoCoordinates, countryCodes);
searchEngine.suggest(textQuery, searchOptions, onHereSearchSuggestionCompleted);
In onHereSearchSuggestionCompleted functions, I have the following code:
if(suggestions.length > 0){
print('explore - onHereSearchSuggestionCompleted - suggestions count > 0');
for (Suggestion suggestion in suggestions) {
print('onHereSearchSuggestionCompleted - current count = ${(suggestions.indexOf(suggestion) + 1)}');
print('onHereSearchSuggestionCompleted - suggestion title = ${suggestion.title}');
print('onHereSearchSuggestionCompleted - place id = ${suggestion.place.id}');
print('onHereSearchSuggestionCompleted - place title = ${suggestion.place.title}');
print('onHereSearchSuggestionCompleted - place address = ${suggestion.place.address.addressText}');
print('onHereSearchSuggestionCompleted - place img length = ${suggestion.place.details.internalimages.length}');
}
}
Please note, you have been able to see this functionality being exposed in flutter SDK due to a bug exposing internal methods in flutter. In general this functionality is not yet public (not in native android and iOS).
We plan to expose this functionality soon, however even when we do, only certain eligible customers would have access to the image content. There should be contractual agreement to be able to see this functionality
I am writing an app to use GPS coordinates obtained by the cell phone itself to retrieve the building name of that location.
For example, if I use this http URL to request with Google Place API:
https://maps.googleapis.com/maps/api/place/search/json?location=40.805112,-73.960349&radius=10&sensor=false&key="YourKey"
I can only get the street name of this coordinate through this.
But if I type "40.805112,-73.960349" in maps.google.com. I can get the exact building name. SO I was wondering how can I use Google Map API to obtain the building name I want.
Thank you very much about this!!!
The first result in the request you provided contains "name" : "Church of Notre Dame", isn't this what you are looking for?
A better request if you are only interested in the place name at this location would be to use the rankby=distance parameter instead or radius and to filter by type=establishment:
https://maps.googleapis.com/maps/api/place/search/json?location=40.805112,-73.960349&rankby=distance&types=establishment&sensor=false&key=YOUR_API_KEY
This would return the closest place at the given location.
I'm looking to create a web application that starts to suggest home addresses as you type. For instance, imagine a pizza delivery company, where you start typing in your address, "1279", and beneath the box it brings up 1279's in the US for people to choose from, like:
1279 Main Street, St. Louis, MO
1279 Tree Street, Baltimore, MD
In this way, it would really mirror maps.google.com in bringing up suggestions as you type.
I've looked through the Google Places and Maps APIs without much success. The GeoCoding one works OK by passing an address parameter through, but often returns no results or really bad ones... nothing like maps.google.com. Plus they're difficult to parse. (The address parts parameters aren't always consistent, meaning that I have to send the formatted address through another parser... not a deal-breaker though.)
Anyone else have any suggestions out there? Thanks! Jeremy
You can improve the Places autocomplete results by passing bounds option when creating it. The example binds it to the map viewport:
autocomplete.bindTo('bounds', map);
In this demo I hardcoded the continental US bounds (plus some of Mexico and Canada)
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input,
{bounds: new google.maps.LatLngBounds(
new google.maps.LatLng(23.730197707069532, -126.14240169525146),
new google.maps.LatLng(50.1805258484942, -65.32208919525146)) }
);
Is there any standard format to supply the address string to Google GeoCoding API to get the most accurate results on map.
For Eg. following query not giving correct result.
http://maps.googleapis.com/maps/api/geocode/xml?address=bloom,Bloomfield,CT,06002,USA&sensor=false
Thanks
Mandeep
I believe the suggested format is:
House Number, Street Direction, Street Name, Street Suffix, City, State, Zip, Country
The results get less specific the less information you can supply, obviously.
In your sample, the geocoder is searching for a street named 'bloom', of which there are similar matches in OH instead of CT. Removing 'bloom' from the query and then searching returns Bloomfield, CT.
Definition of Google address search:
address - The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.
https://developers.google.com/maps/documentation/geocoding/#geocoding
How should I format my geocoder queries to maximise the number of successful requests?
The geocoder is designed to map street addresses to geographical coordinates. We therefore recommend that you format geocoder requests in accordance with the following guidelines to maximise the likelihood of a successful query:
Specify addresses in accordance with the format used by the national postal service of the country concerned.
Do not specify additional address elements such as business names, unit numbers, floor numbers, or suite numbers that are not included in the address as defined by the postal service of the country concerned.
Use the street number of a premise in preference to the building name where possible.
Use street number addressing in preference to specifying cross streets where possible.
Do not provide 'hints' such as nearby landmarks.
https://developers.google.com/maps/faq#geocoder_queryformat
I found the answer incomplete and it lacked a source.
Look here: https://developers.google.com/places/documentation/autocomplete#place_autocomplete_responses
The maps autocompletion API from google returns a much simpler format: "Street address, City, Country"
Now you can use a string like that to search for an address and it should lead to one exact result.
In addition if you use the autocompletion API you will get a unique identifier too which can be used for further detail requests.
The format of the street address greatly depends on the location where you actually are.
In the US "House number, street direction, street name, street suffix" might make sense, in most of Europe it will not lead to successful query.
Addresses in most of EU are different (often "Streetname number suffix") like "Kumpelstraat 25A","Psolevcu 331/26b") and I guess we'd be surprised if we look at some eastern countries.
So if you bind your code to a single area (US, most of EU) you might be good hardcoding the format.
If you want to have a more flexible system you either need to find out propper formating for your target audience or query one of googles APIs to automatically get a proper string.
The one I linked is very good but requires an API key with a free request limit per day.
I stumbled upon this question and found a solution that worked for me:
I think the answer can be found by using component filtering, look at:
https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering
An example in Javascript:
var request = require('request');
var url = "https://maps.googleapis.com/maps/api/geocode/json?" +
"address=Herengracht 180" +
"&components=postal_code:1016 BR|country:NL" +
"&sensor=false";
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
else {
console.log('error', error);
}
});
No need to avoid apartment units. This works:
https://maps.googleapis.com/maps/api/geocode/xml?address=14202+N+42nd+St+Unit+301+33613
"Apt", "Room", and "Suite" work as well
They all return 301 as subpremise and are shown in "formatted_address" as "#301."
Paul sends...
I found that official country codes like "US", "DE", "FR" do not work well. Replacing them with the full country name gives much better results for me.
I did not find a source where that is stated.
Let's say I have a LatLng object, is there any way of checking if it represents a possible location within a city? How can I get the limits of a city?
I'm using Google Map V3.
Have you tried reverse geocoding?
http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding
You could check the formatted address to see if the city matches what you're looking for. I'm not sure how accurate this will be for your application, but it's an option.
function codeLatLng() {
var geocoder = new google.maps.Geocoder(),
latlng = new google.maps.LatLng(40.730885, -73.997383);
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log(results[1]);
console.log(results[1].formatted_address);
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
City limits and other municipalities are constantly re-drawn. There are certain services that exist to help you find them, but I'm not positive that Google keeps a record of city limits inside their data for the Google maps. Here's a discussion in google groups about it. A snippet from that site:
Depending where you are in the world, city limits and other
administrative boundaries are CONSTANTLY being changed, and it's even
sometimes difficult for local governments to keep their data current
because of annexations and other changes. Also, 'city' might be
something relative small or the size of Shanghai. Also, different
countries can also have sometimes conflicting definitions what
administrative unit is the actual definition - a good example is
China. Probably your best approach is to get your data from a local
government or a data supplier and build your own.
You can use Reverse Geocoding in the Google Geocoder API and check the locality entries and perhaps sublocality entries of results returned. http://code.google.com/apis/maps/documentation/geocoding/#Types
Note that this probably won't work so well if you have addresses all over the world and want to know "What city is this LatLng in?" On the other hand, it will probably work reasonably well if you want to know "Is this LatLng within Chicago?" There are areas of the world where the data is fairly complete and sensible, and areas where it is incomplete and/or organized in ways you might not expect. (Apparently, the UK uses "county" and "state" very differently from the USA, for example. Even if I'm wrong about that, you get the idea.)