开发者

Find all parks for a given zipcode with google maps

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 thin开发者_StackOverflow社区k 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.


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]


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/


I just worked on this, I am not using a zip code, but you can take a zip code and get a lat/lng pair. The lat/lng pair already used here(map center set).

This is the query to get parks. I will say it is probably not absolute(only major parks) and there is that 20 limit.

This is from their docs btw, using Places api, also this code is from ReactJS hence ref eg. "current"

const plotParks = (parks) => {
    // array of parks, use marker to plot on map and fit bounds to center
}

const service = new window.google.maps.places.PlacesService(mapTarget.current);

// radius in meters so I added mile to radius, seems correct, formula pulled from SO ha
const radiusInMeters = (Math.round(10000*(radiusMiles*5280 / 3.281))/10000);

service.nearbySearch(
    {location: mapTarget.current.getCenter(), radius: radiusInMeters, type: ['park']},
    (results, status, pagination) => {
        if (status !== 'OK' || !results.length) {
            alert('No parks found near you, try increasing your radius or try a new address');
    } else {
        plotParks(results);
                }
    });

do ctrl+f for 'store' to jump to the code https://developers.google.com/maps/documentation/javascript/places

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜