Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a google map link with directions using latitude and longitude

Good day,

I'm trying to create a google map link that will redirect to a map with directions. I will pass the coordinates in the link. Here is my code:

var latDes = this.items[id].LongitudeWD;
var longDes = this.items[id].LatitudeWD;
var url = "https://www.google.com/maps/dir/?api=1";
var origin = "origin=" + tempLatitude + "," + tempLongitude;
var destination = "&destination=" + latDes + "," + longDes;
var newUrl = new URL(url + origin + destination);

var win = window.open(newUrl, '_blank');
 win.focus();

Here is the sample link that it is currently producing https://www.google.com/maps/dir/?api=1origin=34.1030032,-118.41046840000001&destination=-118.368152,34.059808

As you can see it does not have read the coordinates that I'm passing I want something like this

https://www.google.com/maps/dir/?api=1&origin=760+West+Genesee+Street+Syracuse+NY+13204&destination=314+Avery+Avenue+Syracuse+NY+13204

but if possible instead of using the full address can it be with latitude longitude?

like image 373
Gaston Velarde Avatar asked Jul 15 '17 08:07

Gaston Velarde


People also ask

How do I create a custom Google map?

Create a mapOn your computer, sign in to My Maps. Click Create a new map. Go to the top left and click "Untitled map." Give your map a name and description.


1 Answers

Seems like you missed '&' just before the 'origin' parameter. Also destination parameter have values, seems like not correct. It should be like

https://www.google.com/maps/dir/?api=1&origin=34.1030032,-118.41046840000001&destination=34.059808,-118.368152

like image 119
Pradip Avatar answered Oct 01 '22 13:10

Pradip