0

I want to get get the coordinates of a location using JavaScript. However I'm having trouble with my autocomplete. I came across a similar query but non of the solutions have helped me out.

My code:

<html>
<head>
<title>Geocoding</title>
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script type="text/javascript">
    google.maps.event.addDomListener(window, 'load', initilize);
    function initilize() {
        var autocomplete = new google.maps.places.Autocomplete(document.getElementById('txtautocomplete'));
        google.maps.events.AddListener(autocomplete, 'place_changed', function () {
            var places = autocomplete.getPlace();
            var location = "<b>Location:</b>" + places.formatted_address + "<br/>";
            location += "<b>Latitude:</b>" + places.geometry.location.lat + "<br/>";
            location += "<b>Longitude:</b>" + places.geometry.location.lng + "<br/>";
            document.getElementById('lblresult').innerHTML = location;
        });

    };
</script>
location:<input type="text" id="autocomplete" placeholder="Enter the address"/> <br/> <br/>
<label id="lblresult"></label>

manfcas
  • 1,933
  • 7
  • 28
  • 47
Byron
  • 1
  • 1

1 Answers1

0

Try to have a look at the first answer to this question: Google map api get Latitude and longitude from autocomplete without map

it seems like its the answer for your issue too

Community
  • 1
  • 1
fredeaf
  • 21
  • 6