-1

I can get my current location (using this Google Maps API sample). I would like to output the resulting coordinates to HTML (in a similar way to This JSFiddle).

I believe the JSFiddle uses this code to extract the coordinates, though I am not interested in the 'dragging' functionality:

google.maps.event.addListener(marker, 'dragend', function (event) 
{
    document.getElementById("lat").value = event.latLng.lat();
    document.getElementById("long").value = event.latLng.lng();
});

Any help would be great!

Matt Mac
  • 437
  • 8
  • 22

1 Answers1

0

I found that I was able to output the lat and lng coordinates to HTML by inserting

document.getElementById("lat").innerHTML = pos.lat;
document.getElementById("lng").innerHTML = pos.lng;

below map.setCenter(pos);.

I then called it in HTML with:

<div id="lat"></div>
<div id="lng"></div>

Here is the output:

Geolocation  with coordinates displayed

Matt Mac
  • 437
  • 8
  • 22