Is there a way to determine which states are within circle overlays created by google.maps.Circle? Perhaps using reverse geocoding and getBounds or contains? Does Google provide a way to do this (using the geocoder or some other method), or must a database of Latitude and Longitude points of states be used?
There doesn't seem to be an easy way to do this within Google Maps API.
You can use getBounds() to get a LatLngBounds object approximating the circle. Note though that getBounds() will return a rectangle that approximates the circle, so you might get inaccurate results. To do it more accurately, you'd need to calculate a bunch of points to approximate the circle using something like the Haversine formula in combination with the cirlce's center and radius. The more points you calculate, the more accurate the approximation.
Once you have your set of bounding points, you're still not exactly out of the woods. There does not appear to be a way to use Google's Geocoder API to return all the states in a LatLngBounds. So you'd have to calculate a bunch more points within the bounds and send individual reverse geocode requests for them. And you still might miss a state or two. Overall, yuck.
Another approach, that doesn't seem that much more appealing to me, but who knows: For each state, get lat/lng data for a bunch of rectangular bounds that, when all combined together, approximate the shape of the state. For each state, use intersects() to see if it intersects with your circle.
There may be other possibilities, involving Google Maps API or other technologies, depending on your use case.
Related
I have a number of GPS co-ordinates that describe a route. My intention is to draw a polyline along the route, and then colour segments based on some data I have.
Problem is, the GPS coordinates can occur on the roadside either side of main roads. When using the obvious Directions service solution a lot of "back and forth" occurs as Google tries to get me either side of a split lane road
What I am aiming for is a direct route from A-H passing through every way point. I have considered reverse geocoding the coordinates to a street name and having the directions use the street as a way point, but that picks a specific point on the street that may not be related to the actual route. Single polylines are also not an option as some routes have turns in them.
Is there a way to 'fuzzy' my waypoints so that the directions are happy when passing within a certain radius of the points? If not, has anyone got any other solutions?
Thanks heaps.
Edit: It's also not an option to just not use the middle way points because sometimes the path is not optimal.
Also have tried my own fuzzy coords now, by +- some small value to each consecutive lat/lng pair. Unsurprisingly I ran into OVER_QUERY_LIMIT pretty soon.
Ok, let me preface this question with the fact that I have created a lot of google maps, but they have been strictly markers and polylines denoting routes and a couple with some handler interaction.
Now I am looking to show basically a map of the world, mostly North America and I want to split this continent into my predefined regions with some lats/lngs that I have. Using these regions I want to draw something like a polygon with a light opacity and different color per region.
I then want to use marker clustering but I want the clusters to be specific to these regions. I have looked around but I haven't found an example like this. I have seen pages that say you can do this but not how you would go about doing this. Again, I am definitely a noob when it comes to drawing polygons and using the marker cluster. I know this question is fairly vague but just looking for an example/idea to start off of, and more so I don't want to write a bunch of code against this specific api and then find out that it is not possible.
Any ideas or suggestions are greatly appreciated....Thanks.
It can be done, but will require a rewrite of the MarkerClusterer (probably will simplify it).
You will need to determine how you are going to represent and load the cluster boundary polygons (KML, GeoJSON, native Google Maps API v3 polygons) and probably use the google.maps.geometry.poly.containsLocation(point:LatLng, polygon:Polygon) instead of LatLngBounds.contains to determine which cluster "owns" a marker.
I am making a Google Map (API v3) that searches within a given neighborhood. The neighborhood is not a square but a ton of different points to make a polygon bounding box. I know how to make the polygon but not sure how to get it to search only within the polygon. Below you can see I am using a radius from my center location but I don't need a radius but only a given location.
var request = {
location: centerLatlng,
radius: 800,
types: ["school", "church", "park", "university"]
};
I'm guessing this is a places API request?
https://developers.google.com/maps/documentation/javascript/places
The API doesnt support passing in a artbitary polygon. If you really need to search as such, will just have to do a circle search (as in your example) - and then discard and results that are not in your shape.
Dont think there is a 'is point in side polygon' test in the Maps API itself, but can find code online
https://www.google.com/search?q=point+in+polygon
I have trouble finding any information on how to use the API to:
Search for streets and get some clickable results that returns a LatLng object or something (at least coordinates). So If I search for a street and click on a result, I'll pan to that street (for example).
How can I calculate distance between markers? and possibly, draw lines between them.
All I get is the API but no guides so it's fairly hard figuring out what types to use.
Here is a fiddle showing how this can be achieved:
http://jsfiddle.net/foxwisp/vQGMr/1/
To convert street names to lat/lng you need to use a Geocoder such as the one provided by Google Maps API.
Then, when you get back the results from the geocode, you use the lat lng properties to create a marker. Once your first marker is placed, you repeat the process for your second street address. We nest these calls so that we can be assured of the order of execution due to their asynchronous nature.
Once we have our second marker we use Google's polyline function to draw a line between the two latlng marker points.
Then we use a slightly complicated mathematical equation to do some distance calculations and voila.
The Google Maps API is fantastically documented, hopefully this fiddle will put it into context for you and you can explore each element step by step by reviewing functions and properties in the documentation
I know that I can search for hotels(for example) nearby a node by giving the radius of circle from the center node using google places api. But this returns places which are in other city. The reason is geographically the place is situated within the given radius. But the driving distance differs. Is there anyway to get around this?
The Places Search API will return places within a specified area ranked by prominence (popularity; "rankby=prominence"), or ranked by distance ("rankby=distance") independent of area. There is no option to rank by driving distance.
To get a ranking based on driving distance, you may want to consider using the Places Search API in conjunction with the Distance Matrix API.
https://developers.google.com/maps/documentation/distancematrix/
The Distance Matrix API will return driving, walking, or bicycling distances based on one or more origin locations, and one or more destination locations.