Retrieving different levels of placeIds - google-maps

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!

Related

How to find a place id in Google Maps API if city has an identical name as region, province or municipality

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!

Querying Geonames API to get only city country name

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

Search in specific country only?

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

Google place api search result with place_id returns different location with place_id

I'm using google places api, but it returns the value with different place_id.
I have considered this blog : https://developers.google.com/places/documentation/search
I have requested with place id like this :
https://maps.googleapis.com/maps/api/place/details/json?key=AAIS...
In this url, you can see that the place_id is "EiJ..."
But in the returning json, i have received different place_id.
"place_id" : "AASS...",
"reference" : "df..."
When I have tried with reference, it was the same.
What did I wrong?
Is this the same location with different place_id?
Thanks for your help...
1) Never post your API key on a public forum. Go get yourself a new one.
2) reference has been deprecated, so you don't need to include it
3) EiJG... doesn't look like a Placeid. My guess is that you are trying to look up a value that doesn't exist and you're getting strange behavior.
Run a Place Search and get the Placeid and try again. You haven't posted what you searched for initially so it's impossible to verify that EiJ... really is a valid Placeid.
You can also have more than one place ID associated with a particular place.
In that case, if you request details using one place ID, you can get another ID back (you used the alternate ID, it returns what it considers the primary).
I found your question how to deal with this because I'll be storing information using their primary key and if it changes it will cause issues since the ID initially comes from their search (I'll get the new ID and not realize it is associated with the information I stored).

Finding a Fusion Table entry with a geocoded address

I have a Fusion Tables table containing location data for all of the Congressional Districts in Minnesota here.
I want to have a user enter her address, have the Google Maps API geocode it, and spit out the district in which she lives from the table.
I had hoped I could just pick the closest district by using orderBy: ST_DISTANCE in the query. However, this doesn't always return the district the address is actually located in. For example: http://jsfiddle.net/2vGSB/
Assuming it's even possible, how might I return the district that a set of coordinates is located inside of?
EDIT
After digging through the documentation a bit, I found where: ST_INTERSECTS. It appears to be doing what I need: http://jsfiddle.net/DY49c/