我们如何获得访问者的位置使用谷歌API
How can we get visitor location using google API
<script type="text/javascript" src="http://www.google.com/jsapi?key=API KEy"></script>
if(google.loader.ClientLocation) {
visitor_lat = google.loader.ClientLocation.latitude;
visitor_lon = google.loader.ClientLocation.longitude;
visitor_city = google.loader.ClientLocation.address.city;
visitor_region = google.loader.ClientLocation.address.region;
visitor_country = google.loader.ClientLocation.address.country;
visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById('yourinfo').innerHTML = visitor_lat;
}
else
{
// We implemented the Maxmind method (See source code) or you may want to just leave a message:
document.getElementById('yourinfo').innerHTML = '<p>Whoops we couldnt find you!</p>';
}
我使用这段代码来查找每个访问者的当前位置,但是google.loader.ClientLocation返回空值。还有其他方法可以找到访客的位置吗?
try this: HTML5 - Using Geolocation
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
相关文章:
- 三星智能电视应用程序使用谷歌API
- 在谷歌api v3中使用地理自动完成功能获取邮政编码
- 从谷歌API地理代码的形式字段到数据库
- 从名称或邮政编码获取纬度和经度-谷歌API
- 英国邮政编码谷歌API不返回街道地址
- 用于谷歌API的Jquery
- 根据谷歌 Api v3 书/也用一个按钮添加一个标记
- 谷歌 API :仪表动画
- (谷歌API)单元格引用中的动态工作表和工作表创建脚本的名称
- 谷歌APi 不检索值
- 一个回调两个异步函数,一个是谷歌 api getDistanceMatrix
- 谷歌API正在计算无效地址的距离
- 在文件系统中使用谷歌API
- 如何对谷歌 API 搜索查询进行编码
- 如何使用谷歌API从街景切换到路线图
- 谁能告诉我为什么我不能从谷歌 API 获得城市列表
- 如何使用谷歌 API 网页版从address_components获取地点 ID
- 从经度和纬度谷歌 API 获取邮政编码
- 动态向下面的透视柱形图添加注释 - 谷歌 API
- 谷歌 API 图表日志刻度不起作用