How to plot Google placeid points on a map - google-maps

So, tricky problem... I've put together a bunch of extra attributes to associate with food related places to create a bespoke version map of locations. I've generated this using Google places. I've only stored the placeid, as per terms of service, associating those I've chosen with the extra attributes I've generated.
The challenge I have is: how do I plot these items into a JS Google map? I only want to plot those I've selected and not all food places Google returns on their places api. Due to the terms of service I don't have lat/lon for each location, only the placeid. However given the number of places I'll be looking to plot (thousands in total though obviously less for a small region) , looking then all up on the fly will cripple the system with api calls. Can you plot placeid locations directly or do you need to lookup locations first? And if so how do you filter them only to those in the users region of focus?

Thanks for your question. Unfortunately there is no way of directly plotting PlaceIds on a map without also specifying a lat/lng. As you note the correct way to do this is to perform Places API lookups to resolve the PlaceId.
The performance issue you mention is problematic for the number of points you wish to plot. I refer you to Section 10.1.3(b) of the Places API Terms Of Service; note that there is allowance for limited prefetching and caching activity for the purposes of improving performance.

Related

Possible to get all businesses within an [x] mile radius of an address with Google Maps API?

I'm looking for a solution to gather data on local businesses. In a nutshell, I need to input a street address/coordinates and get a listing of all other businesses that exist in a (for example) 3 mile radius. Will the Google Maps API work for this?
This will be a manual process so the requests will be very minimal: maybe 1 or 2 requests per month. This isn't a script that I am intending to run over and over again in any way to create a high volume requirement.
Google Places API certainly is not designed to gather all businesses within the specified radius. The API returns only most prominent results and doesn't guarantee the complete list. This is not a traditional database search.
In addition there are restrictions in the Terms of Service that prohibit such kind of searches. Have a look at the paragraph 10.4 c (ii).
No creation or augmentation of data sets based on Google’s Content or Services. You will not use Google’s Content or Services to create or augment your own mapping-related dataset (or that of a third party), including a mapping or navigation dataset, business listings database, mailing list, or telemarketing list.
https://developers.google.com/maps/terms#section_10_4

Google Maps private nearby locations on route with directions api

I have a database with about 5000 customers. All saved with lat/lng coordinates.
For our field personnel i have integrated the google maps directions api so that they can calculate the route from our headquarters to the chosen customer. That works perfect.
My problem is that i want to show all additional customers on that route. Has anyone ever done this before or has an idea on how to implement that? In my opinion the only way is to walk the returned array from google directions and do a nearby search with every waypoint.
Any other ideas?
It seems the most sensible answer does indeed seem to be walking the array. Unless you are not tied into your specific database. In which case I would suggest looking here at a previous answer, and consider using a POSTGiS database. This will allow you to perform corridor range searches more easily.
If you are tied to a database then perhaps this link will aid with the implementation of your solution. The library creates bounding boxes along the route within a distance to speed the querying process.

Getting all streets visible in Google map's viewport

I'm trying to build a map with the following algorithm:
Wait for pan or zoom to occurs.
Query for all streets visible in the viewport (extent).
Color every visible street with a predefined color.
Example:
I want to show the numbers of businesses on each street, or the number of crimes committed at each street.
I have a DB which holds this kind of information (streetname, data), but each row doesn't have the location data.
Therefore, after each map zoom or pan, I cannot query all of it by a geographical bounding rectangle, it will be far more efficient to use Google own DB and query it by street names.
I know how to register to pan and zoom events.
I know how to calculate the viewport coordinates.
I know how to color a single street.
How can I get a list of all streets visible in the viewport?
Any other solutions or architectures are welcome.
The preferred solution will not use Google DirectionsService nor DirectionsRenderer since they slow down the map.
My understanding is that what you are asking is not possible from Google API's. Reverse geocoding inside a polygon is not a service they offer. There are some posts on other sites (e.g. https://gis.stackexchange.com/questions/22816/how-to-reverse-geocode-without-google) with the reference gisgraphy.com looking like a pretty neat reverse geocoding tool.
This still does not address your all streets in a polygon problem however. I think your only option would be to get your hands on the data (Open Street Maps) and write the code yourself. Further - if you are going to do this for a large area I would take an approach like I recommended here with grids: https://stackoverflow.com/a/18420564/1803682
I would create my grid elements, and for each street calculate all the grids to which it belongs and store in the database. Then when you search a polygon, you would calculate all the grids the polygon overlaps, and can then test the subset of road data in each of those squares to determine overlap.
I looked into this and abandoned a similar requirement a few months back and still have a desire to implement it. Most of the point/line in polygon work is happening on data created in my application (i.e. not street data) and right now that is the only data I will be including. What I am trying to say is - I hope someone gives you a better answer.
Update:
For what you are asking I still believe you will need to use a mix of your own database based on OpenStreetMap and some kind of grid analysis carried out in advance. If you have some time to commit to the project this should not be too awful to process. The database will be large, and the calculations needed will likely require a significant amount of one-time / upfront processing time. As far as highlighting routes/roads/whatever within the viewport, there are lots of way to accomplish this using the API - example here which I found useful: polyline snap to road using google maps api v3
Also useful: http://econym.org.uk/gmap/snap.htm
Note that one way streets may give some grief if using the directions api to snap to a street and you will likely have to watch for this and correct or reverse the start/end points.
Google would recommend using it's Geocoding Service in order to populate your data base with the co-ordinates. You can then use the LatLng Bounds Class method "contains" to check whether your points lie within the viewport. The advantage of this approach is you only need to geocode the information once and then store this, versus sending coding requests each time the viewport changes.
An alternate efficient way of displaying this kind of data may be to use google fusion tables. this greatly simplifies the integration of the data with the map.

Is it possible to get cities polygonal boundaries like in Google Maps?

I would like to have the possibility to tell if a GPS location is in an inhabited or uninhabited zone.
I have tried some reverse geocoding services out there, but all of them proved useless, because they select the nearest address possible. (I understand why this should be so, it is useful for the purpose of reverse geocoding)
I have noticed in Google Maps, when I search for a city, their boundaries are selected in red dotted well defined line. I would love it to use this, or something similar.
Is there any possible way that Google maps can provide such a service, or something that can solve my problem.
Are there any other web solution or databases that you know of that can give me this information ?
Or maybe I can use any of the reverse geocoding solutions with some parameters (such as restricting the size of searching) to determine if the location is or is not in a populated area?
If you will not find a public service then it gets interesting, and expensive in terms of developping effort.
Public data (world wide) is only available from OpenStreetMap, i think they have such a layer (could be named Land_use (rural, etc.)) This layer is usually used to color a map, look at openstreet map Web page if you find a suitable coloring, that coresponds to your task. (E.g look at green, or gray).
These data are stored in polygons, you would have top extract these polygons (i asume millions of them). Ten you need a fast searching spatial index, like a region Quadtree.
Then you do a "point(lat, lon) in polygon" call, and get the polygon related to your position.
Probaly not all that polygons will fit into main memory, so you must load them on demand (e.g by country).
A variant of this approach is to use a geo spatial database like postgres to store that polygons, and do a DB query.
With that approach most work will be extracting the polygons from OpenStreetMap DB file.
More acurate is data from TomTom, but these can be really expensive.

Compiling a list of all colonies/neighborhoods for a particular city

I want a list of locations (coordinates) for all possible colonies/neighborhoods of some Indian cities. Take for example Delhi. Can this data be obtained with the Places API?
The only thing that comes to my mind is to use a query like -
https://maps.googleapis.com/maps/api/place/search/xml?location=28.540346,77.210026&radius=500&types=administrative_area_level_1|administrative_area_level_2|administrative_area_level_3|locality|neighborhood|street_address|sublocality|sublocality_level_4|sublocality_level_5|sublocality_level_3|sublocality_level_2|sublocality_level_1|subpremise&sensor=false&key=MYKEY
and then keep changing the radius by 500 till the whole city is covered.
Is there a better way of doing this?
Given how often you would need to do this for your map, since caching that data goes against the terms of service, this is not a great approach. If you map gets any decent usage, you'll rapidly hit your quota. Plus you're only get center points of the colonies/neighborhoods. I'd recommend trying to find another source of that data you can download. The Places API was not designed with this in mind.