So, starting with the following query, I can pass user input to the Geocode API and return a json object/response with the locations details.
http://maps.googleapis.com/maps/api/geocode/json?address=10010
My problem is I have the following query with component filters with the country set to the US (United States). However, if you enter in a zipcode like this which is returning an area in Russia it still renders the map and sets the marker for the users current location.
http://maps.googleapis.com/maps/api/geocode/json?address=16721**&components=country:US**&sensor=false
Do I need to check the short_name within the returned object in a simple if statement and choose whether to issue a map request or not?
I thought component filters would restrict the user to search within the country specified? Then, return ZERO_RESULTS if there is not a match.
Any input, feedback is welcomed. Thanks!
Remove stars from from country name:
http://maps.googleapis.com/maps/api/geocode/json?address=16721**&sensor=false&components=country:US
Related
Unable to find map in Sheet after dragging Country / Region into Sheet. there would be some online offline map options which should be explained.
First, make sure that Tableau is recognizing your country field as a country. Click the dropdown on your field to see this:
You should then see the lon/lat(generated) in the col/row as in my image.
If this doesn't work, check the lower right of your sheet for this:
If you see this, Tableau isn't able to match your country names to their recognized names. Click the unknown label and you will be able to define the matches.
You can define the match by searching by country that Tableau recognizes or define it with lat/lon in this screen.
Is there any way to retrieve different levels of placeIds from a specific placeId? Like when you load the address components of a place, you get 'country' 'city' 'region' and so on... But you only get the names of the different levels of position. Is it possible to get the placeId of the country, city.... ?
When I am storing data in the database, I need to also store the country placeId, city placeId together with the original placeId. Do not want to store the name of the places in the database, when a lot of places have the same names.
As you noticed there are no place IDs in address components array. You cannot get this information executing only place details request. Developers have already created a feature request in Google issue tracker:
Add place_id in each address_components
You can star it to add your vote. In the meantime the workaround to get place IDs for country and locality consists in executing a reverse geocoding requests for coordinates of the original place ID with result type locality and country.
For example, I have a place ID ChIJEygrJmSYpBIRUXOjvF0QSLw. The details request for this place
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJEygrJmSYpBIRUXOjvF0QSLw&key=MY_API_KEY
gives coordinates 41.3886875,2.130554. Now I can execute additional reverse geocoding request to get place IDs of locality and country:
https://maps.googleapis.com/maps/api/geocode/json?latlng=41.3886875%2C2.130554&result_type=country%7Clocality&key=MY_API_KEY
The last one gives me
place ID ChIJ5TCOcRaYpBIRCmZHTz37sEQ (Barcelona)
place ID ChIJi7xhMnjjQgwR7KNoB5Qs7KY (Spain)
I hope this helps!
Using the Google places API I am trying to fetch place_id's. I have issues when trying to fetch a place_id when multiple parts of the place location have the same name. For example: The city Utrecht (in the Netherlands) lies in the municipality of Utrecht, Which lies in the province of Utrecht. They all have the same name.
When I fetch Utrecht from the places service it returns the place_id for city (which is the default for maps incase there are multiple options)
I found a hack/solution to fetch the administrative areas: adding localised name of the thing i'm trying to fetch. For example I can use Gemeente(municipality) or Provincie(province)
Is there a way to request specifically the type of region I want to fetch from the API?
I see that the places API has all this information, but sofar my attempts to fetch the place_id for the administrative_area_level_2 or administrative_area_level_1 without modifying the address are futile.
My "fix" works for the Netherlands but I have 12 more European countries with similar issues hence my question.
The most common solution is using the reverse geocoding with a result type filter.
For example, your sample request for Utrecht returns the following coordinate 52.09073739999999,5.1214201
Now use reverse geocoding with result type.
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.09073739999999%2C5.1214201&result_type=administrative_area_level_1&key=YOUR_API_KEY
This returns place ID ChIJPzM8M01oxkcRsFwejVreAAM for admin area level 1
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.09073739999999%2C5.1214201&result_type=administrative_area_level_2&key=YOUR_API_KEY
This returns place ID ChIJA9Xkz5BoxkcRzAM9YkCZGTs for admin area level 2
Hope it helps!
Too much useless json data is being fetched when I request a specific country cities by hitting this URL:
http://api.geonames.org/searchJSON?username=ksuhiyp&country=us&maxRows=1000
This returns too many json fields as you can see, question is hot to play with the query to get only city, country name ?
You can try with the additional parameter style=SHORT
http://api.geonames.org/searchJSON?username=ksuhiyp&country=us&maxRows=1000&style=SHORT
The docs says: style, String SHORT,MEDIUM,LONG,FULL (optional), verbosity of returned xml document, default = MEDIUM
I am using google geocode api for fetching lat long using postal code of singapore
I have tried following to fetch data:
(1) http://maps.googleapis.com/maps/api/geocode/json?address=505468&sensor=false
(2) http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=false
(3) http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=false®ion=sg
But it returns location from India
https://developers.google.com/maps/documentation/geocoding/?hl=fr#RegionCodes
Any other way to get only country specific (Singapore) result.
I have tried following it returns correct result
http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20133224&sensor=false
The correct way of doing this is by providing componentRestrictions
For example:
var request = {
address: address,
componentRestrictions: {
country: 'UK'
}
}
geocoder.geocode(request, function(results, status){
//...
});
To restrict results to a specific country use the component-filtering.
The url should be http://maps.googleapis.com/maps/api/geocode/json?address=Singapore%20505468&sensor=false&components=country:SG
But that's not the issue here, the geocoder-result is wrong, because the result has the country set to SG, but the location is wrong(placed in india).
I'm afraid with the given address(it appears that the postcode doesn't exists), the only thing you can do is to report the wrong result to google.
you can set single country or multiple countries
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Raf&sensor=false&types=(regions)&key=YOUR_API_KEY&components=country:ESP
or
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Raf&sensor=false&types=(regions)&key=YOUR_API_KEY&components=country:ESP|country:uk|country:us
You should be able to use this approach
http://maps.googleapis.com/maps/api/geocode/json?components=country:US|postal_code:5037
remove the address and to the component pass the postal code and make sure if the address has a value let pass another value selected by the user with the postal code to validate your api or else without postal code passed it will leak to another address