Google ローダーで現在のユーザーの場所を取得しようとしています。しかし、なぜそれが機能しなくなったのかわかりません。ページが読み込まれるたびに、google.loader.ClientLocation は null になり、場所を取得できません。私のコード:
<script type="text/javascript" src="https://www.google.com/jsapi?key=MY_APP_KEY"></script>
そして、JavaScriptコード:
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 + '"/>'
);
});
}
}
ありがとう!