3

I have the following code:

function initialize(lat, lng) {
                    window.open("https://maps.google.com/?q=<lat>,<lng>");
                }

Can anyone tell me how to send the lat/lng arguments to Google Maps in the URL?

EDIT - Right now, the values being sent to Maps are "lat" and "lng", NOT their actual values such as 5 and 10. Can someone tell me how to send their actual values in the call to Maps?

geocodezip
  • 158,664
  • 13
  • 220
  • 245
user3033194
  • 1,775
  • 7
  • 42
  • 63
  • Are you looking for [this](http://stackoverflow.com/questions/1801732/how-do-i-link-to-google-maps-with-a-particular-longitude-and-latitude)? – Vadim Gremyachev Jun 13 '15 at 14:32
  • @VadimGremyachev Suppose my lat and lng values are 5 and 10, respectively. I want to pass in those values as parameters to Google Maps. Can you tell me how to do this? – user3033194 Jun 13 '15 at 14:36

1 Answers1

6

Example

HTML:

<a href="#" class="map-btn" data-lat="41.8911684" data-lng="12.507724100000019"> Show Map </a>

JavaScript:

$(function(){
    $('.map-btn').click(function(event) {
      var lat = $(this).data('lat');
      var lng = $(this).data('lng');
      showMap(lat,lng);
    });
});

function showMap(lat,lng){
   var url = "https://maps.google.com/?q=" + lat + "," + lng;
   window.open(url);
}

JSFiddle

Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193