如何在网站上添加谷歌定位信息_HTML5教程-查字典教程网
如何在网站上添加谷歌定位信息
如何在网站上添加谷歌定位信息
发布时间:2016-12-27 来源:查字典编辑
摘要:我们可以很容易地使用HTML5导航对象获取当前位置。请按照以下步骤来获得城市/国家的细节。首先包括jQuery库JavaScriptCode...

我们可以很容易地使用HTML5导航对象获取当前位置。请按照以下步骤来获得城市/国家的细节。

首先包括jQuery库

JavaScript Code复制内容到剪贴板 <scripttype="text/javascript"src="jquery.js"></script> jQuery(function(){ //callnavigatorobjecttogetlatitudeandlogtitute if(navigator.geolocation){ //gettingcurrentlatitudeandlongtitude navigator.geolocation.getCurrentPosition(function(position){ //getlocationdetailsbasedonlatitudeandlongtitudefromGoogle varjsonUrl="https://maps.googleapis.com/maps/api/geocode/json?latlng="+position.coords.latitude+","+position.coords.longitude jQuery.getJSON(jsonUrl,function(data){ varresults=data.results[0]; console.info(results);//checkfirebug alert(results.address_components[5].long_name);//City alert(results.address_components[6].long_name);//State alert(results.address_components[7].long_name);//Country }, function(){ alert('FailedtogetLocationDetails...'); }); returnfalse; }); }});

以上这篇如何在网站上添加谷歌定位信息就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持查字典教程网。

原文地址:http://www.cnblogs.com/mivi/archive/2016/04/16/5398183.html

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新HTML5教程学习
    热门HTML5教程学习
    网页设计子分类