How to Extract Transit Stop locations from Google Maps? - google-maps

I'm building an application that requires the name, long, and lat for the transit stops in my area.
Google Maps API displays this information, but in this scenario I can't use the API and need to extract this information to an XML format.
I'm not sure if this is possible and can't find any reference to this on the web.
Any Ideas how I can extract the transit stop long, lat, and name from Google Maps, preferably to an XML format?

Now it's possible to get this done, check this post:
Detect the nearest transit stop from the given location
And if you want to see it in action try this jsfiddle:
http://jsfiddle.net/doktormolle/aZrvs/

Related

get position of marker in google maps

I would like to extract from google maps a list of marker (bus stop), does exits a way to obtain this list? Can i obtain this information using the google maps API?
More precisely i want to extract the bus stop of my local transport company (CSTP):
https://maps.google.it/maps?q=cstp+Campania&hl=it&ll=40.708751,14.758759&spn=0.489271,0.850067&sll=40.674744,14.792656&sspn=0.06119,0.106258&t=h&hq=cstp&hnear=Campania&fll=40.708751,14.758759&fspn=0.489271,0.850067&z=10
I want some information like position of the marker (long,lat) and the name of the bus stop.
Since now i have tried to use python and the googlemaps library, but other way, like javascript with xml or json, will be well accepted.
i have found out how it should be done. The answer is in the "Nearby Search Requests" of https://developers.google.com/maps/documentation/javascript/places#place_search_requests

Google map search using KML

i am using google map kml field (direct iframe code from gmap)
for showing different locations/shops on map:
Google map #my site,
i need to add a search box from where user can search nearest shops to his/her location...
can any body help me in this out..
It is my understanding that the API does not provide support for searching your provided KML:
google maps API geocode finds nearby KML
Google provides a service called placesService ( https://developers.google.com/maps/documentation/javascript/places ) which lets you make requests to their database of content and return results in the form of KML near a location within some bounded area - but to my knowledge you cannot specify the source to search. (You could try testing the placesService, with a KML layer set on your map and see if it includes your data).
Assuming you are generating your KML from a database, can you could regenerate it appropriately filtered or styled based on the user's search terms. This seems the most likely solution without additional details.
I have done google map search with python. But this one searches hospitals
You need to get google place api and place in code and reconfigure for search,
it will print out name, location address, and website
https://github.com/rockcastle/GoogleMap-Scrapping

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

Get latitude / longitude / Reverse Geocoding without displaying maps

Using a website, I am trying to capture user's latitude / longitude point and based on that grab his current address.
I am able to do this using Google Maps API: geolocation and Reverse GeoCoding. But, my requirement is to get this information without displaying the map. As far as I have read, Google Maps Term of Use prohibits such thing.
Can anyone let me know if there is any other service which can serve my purpose without displaying maps or does Google Maps allow such thing? I am not sure about Bing, Yahoo.
EDIT: On page load, I need to grab user's latitude and longitude and based on that get address information. I am planning to use this address information for displaying nearby locations/places to visit. I have to achieve this without displaying any map.
Yahoo PlaceFinder does it. If you pass through the latitude and longitude in the location parameter and gflags=R, it should return address data.
You'll have to get a Yahoo APP id, but its free and pretty easy to set up.
EDIT: I see you want to do geolocation too, if you can't use google I would investigate html5 geolocation and or use freegeoip.net to geolocate by ip address.
I don't know if Im mistaken this post, but if you read this:
(viii) store or allow end users to store map imagery, map data or geocoded location information from the Yahoo! Maps APIs for any future use;
(ix) use the stand-alone geocoder for any use other than displaying Yahoo! Maps or displaying points on Yahoo! Maps;
It's mean that you can't store the information, or make use of it, without maps.
So the google api and the yahoo api need to have a map...
note- I take that lines from the terms of yahoo: http://info.yahoo.com/legal/us/yahoo/maps/mapsapi/mapsapi-2141.html
EDIT - Now I'm trying to use http://www.geonames.org/export/reverse-geocoding.html It's easy, and works fine for me. I just need the city and maybe a postal code.
I don't think Yahoo requires you to show a map and it also has a higher quota.
http://developer.yahoo.com/geo/placefinder/
There are a number of geolocation APIs - here is a really good one:
https://geoip.nekudo.com/
You merely make a GET request to
http://geoip.nekudo.com/api/{ip}/{language}/{type}
where ip, language and type are optional.
E.g. in Angular 5, using HttpClient:
this.http.get('http://geoip.nekudo.com/api/')
.subscribe(
data => { console.log('SUCCESS! Your coords are lat:', data.location.latitude, 'long:', data.location.longitude); },
error => { console.log('ERROR!', error); }
);
Also, note that the geoip service is written in PHP and open source (https://github.com/nekudo/shiny_geoip) so you can house your own implementation to reduce third party dependencies.

How to extract the lat/lng of pins in google maps?

I want to extract the latitude and longitude of a set of about 50-100 pins in a Google maps web page. I don't control the page and I don't need to do it more than once so I'm looking for something quick and dirty. I've got FireFox with FireBug as well as Chrome and all I need is something that's easier than re typing all the numbers.
Simply click the link shortcut on the map to retreive a URL for the map with pins in.
Next add &output=kml to the end of this url and use the link to retrieve a kml file containing all the pin data.
This kml file is actually in xml format so parsing it should be easy, you just need to look for <coordinates> elements which contain the latitude and longitude data you need.
The kml format is documented here: http://code.google.com/apis/kml/documentation/kmlreference.html
Just saving the .html file and using regex works:
These two reg-ex might be good starting points:
#[0-9]+\.[0-9]+,-[0-9]+.[0-9]+",geocode:"",sxti:"[-#A-Za-z .]+"
{id:"[A-Zloc0-9]+",fid
Google has change a lot the way you can extract information about google.maps and has set some limitations like numbers of queries by day.
To extract the lat and lon of Google maps you need a bit of knowledge about HMTL code and manipulating JSON/XML files. (all can be found in many tutorials.
I recommend you to extrac the data using de "Google Places API" it's VERY EASY! and you can extract about 150k locations by day for free. You have to get an account, activate your privileges of API Places (turn on/off buttom), get you secret KEY and then use a simple URL to extract the JSON/XML file. Here are two great links for that:
[1] https://developers.google.com/places/documentation/search?hl=en
[2] https://developers.google.com/places/training/basic-place-search?hl=en
If you want DETAIL info about the coordinates that you'll get, go to the section "Requesting Place Details" in the second link, that gives you info about what kind of site is that, the phone number and all the comments that users has made, if they are available.
Great coding and greetings!
Depending on the type of the map and whether the pins are set by latitude and longitude or by address, it might even work to just get the link (click on "Link" at the Google Maps page, the URL in the browser might not be the sam) and look for the "sll=[...]" parameters.