Forums

widget google address

webcrea 09 May, 2019
Hi,

Could you add latitude and longitude in the google address widget ?

Thanks
healyhatman 09 May, 2019
While you're waiting, you can add a little javascript to get it yourself
https://stackoverflow.com/questions/13478646/google-map-api-get-latitude-and-longitude-from-autocomplete-without-map
webcrea 09 May, 2019
Thanks Healy
We don't need an API key with this?
healyhatman 09 May, 2019
You sure do. This JS would be AFTER you've used the address widget to get the place ID
webcrea 09 May, 2019
There are several code..?
healyhatman 09 May, 2019
There sure are, do you know a little JS? Pick the one that seems best. Too tired to do it for you at the moment sorry, but it gives you a place to start.
webcrea 09 May, 2019
something I don't understand

I load the api
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyArIMfFJkRRrUBQh1wfcUjYx8dYPfBt5mI&callback=initMap" type="text/javascript"></script>

the script js
prospect_town = jQuery("#prospect_town");
prospect_country = jQuery("#prospect_country");
prospect_state = jQuery("#prospect_state");
jQuery(countries).on("change", function(){
prospect_country.val(countries.val());
});

jQuery(countries).on("change", function(){
prospect_state.val(states.val());
prospect_country.val(countries.val());
getLatLngFromAddress( prospect_town.val(), prospect_country.val() )
});

function getLatLngFromAddress(town, country){

var address = town +", "+ country;
var geocoder = new google.maps.Geocoder();

geocoder.geocode( { 'address': address}, function(results, status) {

if (status == google.maps.GeocoderStatus.OK) {
jQuery('#latitude').val(results[0].geometry.location.Pa);
jQuery('#longitude').val(results[0].geometry.location.Qa);

} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
}

After select a town the console indicate the key is not good!!!

Geocoding Service: This API project is not authorized to use this API. For more information on authentication and Google Maps JavaScript API services please see: https://developers.google.com/maps/documentation/javascript/get-api-key js:55:110
Geocode was not successful for the following reason: REQUEST_DENIED

The key is valid with the google address widget, it works...
healyhatman 09 May, 2019
Places API and the Maps API might be different, follow the link and have a look
webcrea 09 May, 2019
Twice are activate
This topic is locked and no more replies can be posted.