以下から google.loader.ClientLocation を使用していくつかのテストを行いました。
しかし、私はテストのためにnullを取得します:
if (google.loader.ClientLocation)
これは、Google が IP の情報を見つけられなかった場合の動作です。
私は StackOverflow を検索しましたが、それに関する多くの質問がありますが、良い答えはありません。
ネットを検索したところ、次の 2 つのリンクが表示されました。
- https://groups.google.com/forum/?fromgroups=#!topic/google-ajax-search-api/8q_oG-Y9fp8
- http://code.google.com/p/google-ajax-apis/issues/detail?id=586
- https://groups.google.com/forum/?fromgroups=#!topic/google-ajax-search-api/rzoIh4RrtOQ
ナビゲーターの HTML 地理的位置を使用する必要があると言っているようです。
Google API のドキュメントでは、これについては言及されていません。
Google google.loader.clientlocation がまだ機能しているかどうかの確認をお願いします。
私のコードは次のとおりです。
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
</head>
<body>
<script type="text/javascript">
function geoTest() {
if (google.loader.ClientLocation) {
var latitude = google.loader.ClientLocation.latitude;
var longitude = google.loader.ClientLocation.longitude;
var city = google.loader.ClientLocation.address.city;
var country = google.loader.ClientLocation.address.country;
var country_code = google.loader.ClientLocation.address.country_code;
var region = google.loader.ClientLocation.address.region;
var text = 'Your Location<br /><br />Latitude: ' + latitude + '<br />Longitude: ' + longitude + '<br />City: ' + city + '<br />Country: ' + country + '<br />Country Code: ' + country_code + '<br />Region: ' + region;
} else {
var text = 'Google was not able to detect your location';
}
document.write(text);
}
geoTest();
</script>
</body>
</html>