google maps XML Import - google-maps

hi I am trying to develop an application where I import an XML file with addresses and then google maps should tell me the closest places according to my current location.
Can anyone please help me with this.
Thanks

You may use google.maps.geometry.spherical.computeDistanceBetween() to calculate the distance between 2 LatLng's. When you didn't know the LatLng's first request them via the geocoding-service.
This will give you the calculated distance between the points.
When you wan't to get the distance based on a route(e.g. driving-distance) request the directions-Service , the response will contain route and the distance. To request distances for multiple routes with 1 request you also may use a DistanceMatrixRequest

Looks like the perfect use case for Distance Matrix. You'll have to parse the XML file first, and then create a distance matrix request that includes all your locations. That will return a response that gives you the distances to all locations.

Related

Google My Maps: How can I export coordinates from a network-linked KML file?

I've been checking out the documentation for Google's "My Maps" service, and I can't figure out if it will let me do what I need to do.
Our client has a map, created using My Maps, that defines several delivery areas using colored polygons. I understand that it's possible to export a KML file containing the coordinates for these polygons, and that it's also possible to create a network link so said KML file will be updated whenever the map is.
My problem: I don't know what to actually do with the KML file. I need some sort of script that can take the network-linked KML, and return a human-readable set of coordinates that I can use to define delivery areas on the client's site. In other words, they need to be able to edit or create delivery zones on this map, then on their site, bind each polygon to a particular store to determine which store must deliver which orders. There's a lot of complicated stuff going on here, but for this first step I just need to know how to get the coordinates for the separate shapes in a reliable way.
I wish I had some code to post to make this a more useful post, but it's more a question of whether or not this type of functionality is actually possible. Please help me figure this out!
Thanks for any and all help.
The KML file is a XML file then you can inspect the file both server side with a XML parser or client side via JQuery.
this is an essential javascript sample for a client side approch:
var request = new XMLHttpRequest();
request.open("GET", filename, false); // filename = kml_filename
xmlDocObj = $($.parseXML(request.responseText));
var placemarks = xmlDocObj.find("Placemark");
placemarks.each(function (index) {
... your parsing for the geometry object and coordinates content you need
}

Google Maps Directions weird route path

I developed an app that sends GPS points to a server and the server convert those GPS points into a path, which is shown in a map.
Now the server makes a call to Google Maps Directions service and gets a response. From that response I use the value overview_polyline, which based on the documentation:
Contains an object holding an array of encoded points that represent
an approximate path of the resulting directions.
The problem is that sometimes the line I get is really weird. Sometimes it gives me a path where there's no street at all.
Here are some screenshots to describe my problem. The yellow marker is the start point (A), and the blue marker is the end point (B).
So I asked Google to give a route from A to B, with driver mode, so it shows the actually path.
And this is the result:
This is the API call I use. My question is: Any idea why would it return that path?
http://www.geocodezip.com/v3_example_geo2.asp?addr1=53%20Imperial%20Avenue,%20Westport,%20CT%2006880,%20USA&addr2=2%20Harborview%20Road,%20Westport,%20CT%2006880,%20USA&geocode=1&geocode=2&type=m
Looks to me like the encoded polyline is not being rendered correctly. How is your code handling that?
example using the geometry library decodePath function
Looks to me like Google broke their polyline encoding.
If I paste it into here (which admittedly doesn't expect polylines, it expects polyons)
I need to escape the "`", change:
{pazFraw~L|#|#f#^`#N\\?XIx#a#n#[
to:
{pazFraw~L|#|#f#^\`#N\\?XIx#a#n#[
to make it have a more reasonable shape.

rendering a json with direction service

when i make a request for a specific latlang direction service responses with the same json. so instead of making the same requests always, i want to store the json somehow.i tried parsing the json and sent to my function which i render the responses, but it didn't work. is something like this even possible?
var direction = JSON.parse('{"routes":[{"bounds":......}');
directionRenderer.setDirections(direction);
It's not possible by using directionRenderer.setDirections() , because not all properties of a directionsResult may be stored in JSON.
But you may of course draw the route on your own, fetch the important details (LatLng's, descriptions etc. out of the directionsResult and use them to 1. draw a polyline and 2. providing route-details)

Only getting city from GPS coordinates

Is there a way to only get the city name from gps coords ?
curl 'http://maps.google.com/maps/api/geocode/xml?latlng=43.7,7.26&sensor=false'
gives me several addresses, much more than I need. I did not find any filter options in the query, I would expect something like an additionnal "q=city" for instance.
I found GeoLite. At least for those who need the centre location of cities using an integrated database.
I finally used geocoder module (for node.js) and parse the json response to get the locality.

Get points from a Gdirections route

I'm trying to get a collection of points (latitude,longitude) between 2 adresses. The points needs to be on a valid tracfic route. I currently use Gdirections to create a route between 2 adresses. Is there a method to get somepoints allong this route? To me it seems impossible...
thx in advance!
You can get the returned polyline using GDirections.getPolyline() Then you can use GPolyline.getVertex(index:Number) to retrieve the vertex points along that route.