zoukankan      html  css  js  c++  java
  • 获取当前地址

    /*获取当前位置start*/
    function getLocation(elem)
    {
    if (navigator.geolocation)
    {
    //navigator.geolocation.getCurrentPosition(function(position){
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(position){
    //var W_ = position.coords.latitude;//维度
    //var J_ = position.coords.longitude;//经度
    var W_ =position.point.lat;
    var J_ =position.point.lng;
    Select(W_,J_,elem);
    });
    }
    else{
    alert("无法获取当前位置");
    }
    }
    var SAMPLE_POST_REVERSE = 'https://api.map.baidu.com/geocoder/v2/?ak=密钥&callback=renderReverse&s=1';
    var safe = '';
    var pois;
    function showReverseURL(latitude,longitude,elem)
    {
    safe = SAMPLE_POST_REVERSE;
    safe += "&location=" + latitude + "," + longitude;
    safe += "&output=json";
    safe += '&pois=' + pois;

    };

    function Select(latitude,longitude,elem)
    {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    showReverseURL(latitude,longitude,elem);
    var newURL = safe.replace('密钥', '密钥值');
    script.src = newURL;
    document.body.appendChild(script);
    };

    function renderReverse(response)
    {
    var val = '';
    if (response.status)
    {
    alert("无正确的返回结果");
    return;
    }
    var location = response.result.location;
    if(response.result.formatted_address == "")
    {
    alert("无正确的返回结果");
    }
    else
    {
    val=response.result.formatted_address+response.result.sematic_description;
    }

    if (pois == 1)
    {
    val="";
    }
    window.elem.val(val);

    // $("#address").val(val);
    return;
    }
    /*获取当前位置end*/
  • 相关阅读:
    java
    EL表达式详解
    SVN的安装与配置
    javascript高级程序设计学习笔记
    java基础知识
    javascript高级程序设计学习笔记Chapter 5: Reference Types
    javascript模态,非模态窗体
    javascript执行顺序
    javascript的执行顺序2
    自动补全+汉字拼音双查(1)数据库
  • 原文地址:https://www.cnblogs.com/wanan-01/p/7474519.html
Copyright © 2011-2022 走看看