简体   繁体   English

未定义地理位置

[英]undefined geo location

I am trying to obtain the client's current location using google's jsapi, but I am getting 'google.loader' as undefined. 我正在尝试使用Google的jsapi获取客户端的当前位置,但是我正在获取未定义的“ google.loader”。 ANy idea why this could occur? 知道为什么会这样吗? Given below is my code snippet i used. 以下是我使用的代码段。

$.getScript('http://www.google.com/jsapi', function() 
{
if(google.loader.ClientLocation) {
var visitor_lat = google.loader.ClientLocation.latitude;
var visitor_lon = google.loader.ClientLocation.longitude;
var visitor_city = google.loader.ClientLocation.address.city;
var visitor_region = google.loader.ClientLocation.address.region;
var visitor_country = google.loader.ClientLocation.address.country;
var visitor_countrycode = google.loader.ClientLocation.address.country_code;
console.log("Your location is: " + visitor_country);
}});

You're only loading http://www.google.com/jsapi which is the basic google library, you can use that library to load the actual google modules, like 'ClientLocation'. 您只需要加载http://www.google.com/jsapi这是基本的google库),就可以使用该库加载实际的Google模块,例如“ ClientLocation”。

Use something like: 使用类似:

google.load("my_library", function () {
    google.my_library; // is not available
}

Change my_library to whatever you need. my_library更改为您需要的任何内容。

I have had the same problem today. 我今天有同样的问题。

If you are using phone browser, and if you have the localization disabled for the browser, the api not load correctly and throws an js error (Parse error). 如果您使用的是手机浏览器,并且已禁用浏览器的本地化,则api无法正确加载,并引发js错误(解析错误)。

I have test it with a iphone and android phone. 我已经用iPhone和Android手机对其进行了测试。

Turn on localization for the browser and works fine! 打开浏览器的本地化功能,一切正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM