Get latitude and longitude based on location name with Google Autocomplete API

前端 未结 7 1600
终归单人心
终归单人心 2020-11-30 20:49

I have a textbox in my page which gets a location name and button with text getLat&Long. Now on clicking my button I have to show an alert of latitude

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 21:26

    The below is the code that i used. It's working perfectly.

    var geo = new google.maps.Geocoder;
    geo.geocode({'address':address},function(results, status){
        if (status == google.maps.GeocoderStatus.OK) {              
            var myLatLng = results[0].geometry.location;
    
            // Add some code to work with myLatLng              
    
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
    

    Hope this will help.

提交回复
热议问题