convert address into google maps api coordinates

Asked

Viewed 1,190 times

-1

I’m making a site where I use Google Maps API to route the buses and I need to convert the captured address into an input in coordinates, and display them in another input to keep track of (I’m doing this with a js Alert and it’s driving me crazy).

I’m picking up the coordinates together in the following code:

    geocoder = new google.maps.Geocoder();
                geocoder.geocode({'address':start}, function(results, status){
                    if( status = google.maps.GeocoderStatus.OK){
                        latlng = results[0].geometry.location;
                        alert(latlng);
                    }

I would like to take the lat and lng separately in an input each to stop using Alert

  • a suggestion. Use console.log instead of Alert rsrs

  • Vc wants to pass the latitude and longitude value and pass to two inputs?

  • yes, I want to pass the latitude to one input and longitude to another, but the way it is currently playing both in an Alert :(

1 answer

2


The "Location" object is an instance of the Latlng class, access the reference

Therefore, the code to search for the separate latitude and longitude fields is:

document.getElementById('lat').value = latlng.lat();
document.getElementById('lng').value = latlng.lng();

If your goal is just debug, it is simpler to use the console.log function and observe the result in your browser console.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.