I'm trying to retrieve current user location by Google Loader. But I don't know why it stopped work. Any time the page is loaded, google.loader.ClientLocation is null and can't get any location. My code:
<script type="text/javascript" src="https://www.google.com/jsapi?key=MY_APP_KEY"></script>
And then the javascript code:
google.load("search", "1", {callback: initialize});
function initialize() {
if (google.loader.ClientLocation) {
var userCountry = google.loader.ClientLocation.address.country;
var userLocation = google.loader.ClientLocation.address.city;
var userRegion = google.loader.ClientLocation.address.region;
var userCountryCode = google.loader.ClientLocation.address.country_code;
$.ajax({
url: "${createLink(controller: 'util', action: 'userLocation')}",
data: { city: userLocation, region: userRegion, country: userCountry, countryCode: userCountryCode }
})
.done(function(data) {
$("#userLocation").html(userLocation + ", " + userRegion + " - " + userCountry +
' <img src="' + data + '"/>'
);
});
}
}
Thanks!