Find all parks for a given zipcode with google maps - json

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.

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

Related

How to find municipality and postal code that are in range from coordinates?

Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.

Google Directions API Result is different from Google Maps result

I am developing an app that displays the Distance & path between 2 distances. In this case I have used following addresses:
Source: Major Bhola Ram Enclave
Destination: Ring Road Mall, Sector 3, Rohini, New Delhi, Delhi
When I use Directions API then I get following result, see image below:
But, when I search these addresses in Google Maps then I get different Result.
Click here to see Google Maps result
I searched a lot about this but I couldn't find any reason/solution for this.
Please guid me in right direction.
Thanks.
Those are not addresses, they are places. If you want a similar result to Google Maps, you need to use the placeId or the coordinates returned for that place from the places service in the directions request.
http://www.geocodezip.com/v3_example_geo2.asp?addr1=Major%20Bhola%20Ram%20Enclave&addr2=Ring%20Road%20Mall,%20Sector%203,%20Rohini,%20New%20Delhi,%20Delhi&place=1&place=2
(uses the results from the place service)

how to get the complete address(es) using a business name?

I know that google maps's JSON return includes a "formatted_address" that gives you the full readable address but I've tested it on a couple of places with no success, the lat and lng coordinates aren't correct either. If I manually search it using maps.google.com it would be correct so I know the input is specific enough. How can I use the API to do this? What if the input is vague? Can I get a JSON return that includes all possible locations? (i.e. McDonalds in NYC will surely return many coordinates)
example:
http://maps.googleapis.com/maps/api/geocode/json?address=time+square+nyc&sensor=false
this returns the CORRECT coodrinates and full address that I can use.
http://maps.googleapis.com/maps/api/geocode/json?address=amc+loews+boston&sensor=false
this does not. but of course if i just search "amc lowes boston" manually it returns the correct address on google maps.
I think you're looking for Google Maps' Places Library.

Detect the nearest transit stop from the given location

I need to get all the nearby public transit information within certain distance from a given location. The type of public transit can be either bus, train, etc..
Here is what I meant:
If I use Google Map to query "Transit Stop near a Location (e.g. Bugis Street Singapore)", then it will return us all the nearby Transit Stop that I want. Like the one shown in the picture. But I need its API to get those details out. (such as bus service No, bus stop ID, etc. as shown in the picture). But I couldn't found any.
Here is what I've tried
I have tried using the Google Map Nearby Place API to search for a place with the type of transit_station, bus_station, train_station,etc... But they all return Zero Result. I could only use this API to search for Nearby Place of Interest, but not nearby transit.
I've also check Google Transit API, but I only found API to insert transit data to Google but Not to extract it out. I think Google didn't publicize the transit API yet.
Additional Information
I have check the site Gothere.sg. And confused How? because they able to detect the nearby transit. Is it only because they specify the direction "From-To".
I have read a pretty similar question on Detecting nearby transit. Perhaps It is not yet possible if we use Google APIs.
But nothing is impossible for me
Last Resort
As Last resort, I also check with the provider, publictransport.sg. I hack around with the API. And found out that it can provide me with a transit stop with some coordinate. But it lack a nearby API which found on Google Map.
So one workaround I could think of at the moment, is to use the provider in this case was publictransport.sg which give me the Stop ID and its coordinate. To do this, First, I have to translate the location name using the Google GeoCoding API into Coordinate then I have to create my own nearby calculation to find the nearby station by comparing the searched Coordinate against all the station coordinate that the provider have.
Now, it is possible for me, but very painful :-)
Back to the Question:
Is there a way to retrieve all transit stop data from a given location (either using Google Maps API or Any other API)? and How did u do that?
Thanks
At least thanks for reading my lengthy question. I appreciate any help from you.
Well, you could use the places-API to find the nearest transit-stops, it works fine for me for the given location.
Just do a request with the parameters:
location (latlng-object of the given location)
radius(radius to search for in meters)
types(array of valid types, e.g. ['bus_station','subway_station'])
Checkout the fiddle: http://jsfiddle.net/doktormolle/aZrvs/
For retrieving further details(bus service No, bus stop ID) I don't have any good idea right now.
There should be a way, those data on maps.google.com will be retrieved by using AJAX, so there is a ressource. But as long as there is no public API to fetch those results it would not be legal to use this ressource.
Adding &output=json to your initial query (http://maps.google.com/maps?q=transit%20stop%20near%20New%20Bugis%20Street%20Singapore&output=json), is not a legal way to get this information?
You can still enumerate all of Bus Service Number, Bus Stop ID (Station Names) after getting the google-places-api details, as #Dr.Molle: said.
Open the webpage of detail['result']['url'], and then XPath the string of bus ID list.
Below is an example to get Taipei's bus Info around a location (latitude, longitude). More detail implementation see https://github.com/MikimotoH/gisTools/blob/master/google_place.py
places = get_web_json(
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?' +
'key=%s&location=%f,%f' % (apikey, lat, lng) +
'&rankby=distance&language=zh-TW&types=bus_station')
if places['status'] == 'OK':
for result in places['results']:
placeid = result['place_id']
detail = get_web_json(
'https://maps.googleapis.com/maps/api/place/details/' +
'json?key=%s&placeid=%s' % (apikey, placeid) +
'&language=zh-TW')
station = detail['result']['name']
loc = detail['result']['geometry']['location']
buspage = get_webpage(detail['result']['url'])
tree = lxml.html.document_fromstring(buspage)
bus_elm = tree.xpath("/html/body/div[1]/div/div[4]/div[4]/div/div/div[2]/div/div[2]/div[1]/div[2]/div/div/div[2]/div/table/tr/td")[0]
buses = list(filter(lambda s: len(s.strip()) > 0,
bus_elm.text_content().strip().split()))
yield (station, float(loc['lat']), float(loc['lat']), buses)
The Transitland APIs can answer your question. For example, try using the Transitland v2 REST API stops endpoint like this:
https://transit.land/api/v2/rest/stops?lat=xxx&lon=xxx&radius=1000&apikey=xxx
More information on the endpoint parameters and response at https://www.transit.land/documentation/rest-api/stops

Google Maps API: Searching

I'm working on a shipping system for my company where user's enter (along with a bunch of other information) the destination that something needs to get shipped to. The system that we are migrating from just used this information as static text, so people would enter shorthand addresses such as "Alsip 60801".
My original thought was that that sort of shorthand text would work perfectly with Google Maps API, because I can type shorthand things into maps.google.com, and it generally works.
So, I wrote up some code to run geocoding on their shorthand inputs. To my unfortunate surprise, the results returned from the geocode search were greatly different from those that are returned from maps.google.com.
For example, when I search for "Alsip 60801" on maps.google.com, I get Alsip, IL 60801. That's correct. But when I search using the Google Maps API, I get some Alsip up in Canada.
Is there another search function that I should be using for the Google Maps API? Or some sort of flag that I am missing?
For reference, this is the short version of my code:
var geocode = new google.maps.Geocoder();
geocode.geocode( {'address': 'Alsip 60801' }, function(results, status) {
console.log(results[0].geometry.location);
//Outputs the LatLng of a Canada address
});
Edit 1: I forgot to mention, I did try setting the region on the geocode request. I set it to us, and got the same results.
Update - Answered: I marked #Jitimaro's answer as correct, because tacking the country code onto the end of the results does seem to work. I'm not sure if that will work with every sort of input (it's hard to predict shorthand address formats), but it seems to work fine for now.
However, I actually am handling this a different way. Instead of just tacking a country code onto the end of the address, I'm actually providing a LatLngBounds parameter on the end of my geocode request. That gives all addresses within my bounds preferential treatment as it is searching.
When you search with the website you should get a preview like this: http://maps.google.com/maps?q=Alsip+60801. When you search a reverse geocode you must parse the result to match your country http://maps.googleapis.com/maps/geo?q=Alsip+60801. You can check the different url with a network sniffer. Or you can add the country to your url http://maps.googleapis.com/maps/geo?q=Alsip+60801+USA.