问题
I'm trying to use the Google maps geocode API to return all parks for a given zip code. It seems that if I have a park name I have no problem returning the data. Such as http://maps.googleapis.com/maps/api/geocode/json?address=Kerry+Park+98122&sensor=false
However, if i search for parks for a zip code http://maps.googleapis.com/maps/api/geocode/json?address=Parks+near+98122&sensor=false
I get any result for the zip code with parks
in the address. I tried using lanlng
but that has the same problem. It seems that Google doesn't allow types[]
in query just the results which is unfortunate.
If I search for "parks near 98122" on maps.google.com I get all the results but it doesn't seem to be using the same API.
I requested a Google maps Places api key which I think is what I need.
I guess my questions are:
a) am I missing something here?
b) I'm not stuck with Google API are their others that will output JSON results for all parks by zip. I looked briefly into Bing and Yahoo to no avail.
Thanks.
回答1:
The Google geocoder API doesn't have a provision for specifying a "type" such as "park" in the query. It will identify the feature type in the response, but you can't put it in the the request.
You might be able to do what you want in the Google Places API, now out for developer preview. I haven't tried it. You still can't specify a type in the request, but you specify a location and radius, and it returns all places, and each place has one or more associated type codes (which might include park). You can search through the returned results to see if parks appear. See http://code.google.com/apis/maps/documentation/places/
回答2:
Use Google Places API and the text search.
Change the [zipcode] and the key [apikey]:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=park+in+[zipcode]&key=[apikey]
来源:https://stackoverflow.com/questions/5753122/find-all-parks-for-a-given-zipcode-with-google-maps