• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    如何在网站上添加谷歌定位信息

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

    首先包括jQuery库

    JavaScript Code复制内容到剪贴板
    1. <script type="text/javascript" src="jquery.js"></script>   
    2.   
    3. jQuery(function() {   
    4.   
    5.   //call navigator object to get latitude and logtitute   
    6.   
    7.   if(navigator.geolocation) {   
    8.   
    9. //getting current latitude and longtitude   
    10.   
    11. navigator.geolocation.getCurrentPosition(function(position) {   
    12.   
    13.   //get location details based on latitude and longtitude from Google   
    14.   
    15.   var jsonUrl = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+position.coords.latitude+","+position.coords.longitude   
    16.   
    17.   jQuery.getJSON(jsonUrl , function( data ) {   
    18.   
    19.      var results = data.results[0];   
    20.   
    21.               console.info(results); //check firebug   
    22.   
    23.      alert(results.address_components[5].long_name); //City   
    24.   
    25.      alert(results.address_components[6].long_name); //State   
    26.   
    27.      alert(results.address_components[7].long_name); //Country   
    28.   
    29.   },   
    30.   
    31.   function(){   
    32.   
    33.      alert('Failed to get Location Details...');   
    34.   
    35.   });   
    36.   
    37. return false;   
    38.   
    39.     
    40.   
    41.        });   
    42.   
    43.   }});  

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

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

    上一篇:HTML5打开本地app应用的方法
    下一篇:HTML5中使用postMessage实现Ajax跨域请求的方法
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    如何在网站上添加谷歌定位信息 如,何在,网,站上,添加,谷歌,