如何在网站上添加谷歌定位信息_html5教程技巧

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

首先包括jQuery库

JavaScript Code复制内容到剪贴板“text/javascript” src=”jquery.js”>       jQuery(function() {         //call navigator object to get latitude and logtitute         if(navigator.geolocation) {       //getting current latitude and longtitude       navigator.geolocation.getCurrentPosition(function(position) {         //get location details based on latitude and longtitude from Google         var jsonUrl = “https://maps.googleapis.com/maps/api/geocode/json?latlng=”+position.coords.latitude+”,”+position.coords.longitude         jQuery.getJSON(jsonUrl , function( data ) {            var results = data.results[0];                     console.info(results); //check firebug            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(‘Failed to get Location Details…’);         });       return false;                      });         }});  

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

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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
编程技术

用HTML5 Canvas API中的clearRect()方法实现橡皮擦功能_html5教程技巧

2025-3-29 21:00:03

编程技术

HTML5 Canvas绘制文本及图片的基础教程_html5教程技巧

2025-3-29 21:01:11

0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
私信列表
搜索