convert address in coordinates google maps api

-1

I'm doing a site in which 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 go with it (I'm doing this with a js alert and it's driving me crazy.)

I'm getting 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 get the lat and lng separated in an input each to stop using the alert

    
asked by anonymous 06.11.2015 / 00:40

1 answer

1

The "location" object is an instance of the LatLng class, access the reference

Soon, the code to search for the separated latitude and longitude fields is:

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

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

    
06.11.2015 / 01:34