Reputation: 229
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
but if possible instead of using the full address can it be with latitude longitude?
Upvotes: 15
Views: 25726
Reputation: 516
Seems like you missed '&' just before the 'origin' parameter. Also destination parameter have values, seems like not correct. It should be like
Upvotes: 38