Draw route and get distance from coordinates - google-maps

we're working on a web app for fleet management.
We collect coordinates from vehicles and we would like to show a map with the "history" routes and the km traveled.
Problem is that the position sometimes is out of the road, so route API shows a strange route. This translates into a "drawn route" with a strange path and a lot of km more. Another problem is that the route is the one currently suggested, for example for work in progress
We are also trying to use polylines but that means that the line does not follow the road (ex curved road).
Do you have any suggestions?
thanks

See https://developers.google.com/maps/documentation/roads/snap for snapping the gps locations to the roads and interpolating the gps locations to account for roads that are not straight.

Related

Google Maps draw area / shape / region and export as latitude longitude

I need a Google Map with marked up areas with different colors.
GADM data
The first article I came across was this one:
https://ourcodeworld.com/articles/read/830/how-to-highlight-an-area-city-state-or-country-in-google-maps-with-javascript
It links to this service for getting coordinates:
https://gadm.org/download_country_v3.html
The problem is that there are too many points so it would end up with 3MB for an embedded map.
Google Maps draw
Then I tried Google Maps service to draw a shape. While it works, I could not find any export function to get the longitude and latitude.
https://www.google.com/maps/d/u/0/viewer?mid=1IlydZDXB-tkN8K8pAR57BRFqBOTv3c8z&ll=59.681023024095936%2C18.40997752499993&z=9
Question
How can I draw an area on a map and then get longitude and latitude for the points? On Google Maps, a tool or something else does not matter.
I solved my problem very differently. I simply used an svg file of just the country and highlighted areas there.
I used this site:
https://simplemaps.com/custom/country

Why is google streetview not displaying image for some coordinates?

I am having an issue where some coordinates are providing correct streetview image while others are off by several lots. For example, the coordinates for 42.4025192834409,-83.1636018491871 in streetview bring me to the intersection nearby. If I enter those coordinates into google maps the pin location is correct but then I can't drag the streetview icon in that section. Is there anything we can do differently with our coordinates so that they go to correct location for streetview?
When I search for the address it works as you are seeking. I think this is the discrepancy you are experiencing:
https://developers.google.com/maps/documentation/streetview/intro
The Google Street View Image API will snap to the panorama photographed closest to this location. When an address text string is provided, the API may use a different camera location to better display the specified location. When a lat/lng is provided, the API searches a 50 meter radius for a photograph closest to this location.
You may want to try reverse geocoding.
Try again now.
https://maps.googleapis.com/maps/api/streetview?size=640x480&location=42.4025192834409,-83.16360184918&fov=90
When I read your question two days ago, it was actually getting the wrong panorama. I tried again today and it finally got the closest panorama to those coordinates. I guess it was an issue on Google's end.

How to get all nearby roads in points specified radius?

I have some latitude, longitude and radius in meters and i need to get all roads names in that radius... The nearest road i can get like this http://maps.googleapis.com/maps/api/directions/json?origin=55.685025%2c21.118995&destination=55.685025%2c21.118995&sensor=false&mode=driving. It would be in routes[0].legs[0].start_location. But is it possible to get all roads in 200 meters?
I also found this Google Maps: Given a point, how to find all points at a given road distance? in which on screen is show situation almost like mine, but the link is broken.
You can use the direction api when a road intersects the circumference. Then you can
subdivide the circle into smaller egments and feed it to the direction api. Here is an example:How do I calculate a point on a circle’s circumference?.

Street view google map URL and coordinate query

I am currently converting a number of simple Google Map Street View links into URL requests for static Street View images. Most of the conversions work except for a few odd instances which I am struggling to explain.
Firstly, in the normal way, I access Google Maps as a regular user and find the position on a road in London I want to see called London Wall, and I point upwards and eastwards. This is the resulting link: (please test it and you will see a prominent building called Winchester House with a smooth curved exterior in the flash Street View used by Google consumers):
http://maps.google.com/maps?q=Winchester+House,+London+Wall,+London,+United+Kingdom&hl=en&ll=51.516287,-0.083299&spn=0.007838,0.018196&sll=51.522309,-0.080509&sspn=0.06227,0.145569&oq=winchester+house,+london+wall&hq=Winchester+House,&hnear=Wall,+1+Denbigh+Rd,+London+W11+2SJ,+United+Kingdom&t=m&z=16&layer=c&cbll=51.516305,-0.083422&panoid=U6g4EoZt5cM4e2WFiDLoxA&cbp=12,268.2,,0,-16.66
Secondly, if I adopt the same coordinates from the above link to get a Static Street View Photo via the following URL request, I get a different result:
http://maps.googleapis.com/maps/api/streetview?size=800x600&location=51.516305,%20-0.083422&fov=110&heading=268.2&pitch=16.66&sensor=false
This second view is still looking westwards along London wall, but the Static Street View photo is set approximately 50+ metres on the wrong global coordinate (please try the link above and you will see a footbridge is in front of Winchester House, which lies in the distance).
This is confusing when both URLs above appear to be using the same global coordinates. (I have referenced the same coordinates for many other different links and both URLs usually show the same view).
I would be grateful for anyone's help on this and understand whether anyone has experienced similar problems or inconsistencies with different Google coordinates.
Many thanks
Mike

Placing Hotels having same Geo-Coordinates

I am facing a problem that in a teretorry I have to display 6 Hotels with info windows but the problem is that all having the same geo coordinates.
Is there a way that despite having the same coordinates all are visible?
Thanks
I guess the hotel coordinates (latitude/longitude) are from a different API like expedia or so.. The hotel APIs sometimes provide only area coordinates.
I would try to solve the problem by the address and not by the coordinates. Just get the hotel address from the hotel API and use Google Maps Api to show the hotels by that address.
If that isn't an area coordinate you can use a special marker as a placeholder and print all information in the infowindow.