Google api 谷歌加载器不再工作了
我正试图通过Google Loader检索当前用户位置。但我不知道它为什么停止工作。每次加载页面时,google.loader.ClientLocation都为null,无法获取任何位置。我的代码:Google api 谷歌加载器不再工作了,google-api,google-loader,Google Api,Google Loader,我正试图通过Google Loader检索当前用户位置。但我不知道它为什么停止工作。每次加载页面时,google.loader.ClientLocation都为null,无法获取任何位置。我的代码: <script type="text/javascript" src="https://www.google.com/jsapi?key=MY_APP_KEY"></script> 然后是javascript代码: google.load("search", "1"
<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 + '"/>'
);
});
}
}
谢谢