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.
Related
I am wondering if it's possible in any way to get a list of businesses that have done a Google Virtual Tour (basically a Street View, for businesses) by querying in Google Maps API.
I was hoping that perhaps the Places Library might contain this information in a response, but no dice. This is kind of visible in an everyday map (see Hotel Boulderado) but I don't think the information is included in any kind of query I can do.
I also saw a few questions dealing with finding a Street View by a specific LatLng - I'm looking for a more general, area-based search.
Any ideas or things I missed?
I was hoping that perhaps the Places Library might contain this information in a response
Places API can provide you a "list of businesses" in an area by trying to filter it up with specific Place Types. You are, however, limited to the constants the API provides. If you're using PlacesService, you can use nearbysearch which I think is more appropriate to your case.
I also saw a few questions dealing with finding a Street View by a specific LatLng - I'm looking for a more general, area-based search.
I'm not sure what you mean by "area-based search", but Street View on a specific LatLng can be tricky since its only available on some areas. The Explore StreetView site highlights what countries currently have data (zooming in suggests that it doesn't necessarily captured the whole country; mostly are road routes, etc.)
A StackOverflow entry indicates a way to handle if StreetView is available or not.
Hopefully the answer raised some clarifications in your end.
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.
I have a programming task related to maps.
We are going to ask people where they live, where they work and potentially other common 'locations' they drive to. We will then map the routes to/from these locations (likely via google maps/places api). We then need to figure out if the person driving these routes has a likelihood of driving past certain locations (a list of ~500 specific landmarks we'll specify). I am thinking I can achieve this with google maps/places, but I'm relatively new to mapping related tasks.
Is what I am saying achievable via these apis and can you direct me to any docs or tutorials?
I'm thinking that we decide whether a person 'drives past' a certain location can be achieved by calculating distance b/w landmark AND the closest point to it on the route(s), I'm just not sure HOW to do this (or if that is the best solution).
Is there a way to determine what traffic condition is at specified concrete point or street? I figured out i could just "ask directions" and divide by length but it would be more convenient to have such stuff in the api, i.e., get the full list of streets where is currently a traffic jam in one city.
I have been looking for those API's myself. Dont think they are available.
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.