Foxtable(狐表)用户栏目专家坐堂 → XXXXX微信里获取用户地理位置,有没有比较好的贴子,推荐下,谢了!


  共有8153人关注过本帖平板打印复制链接

主题:XXXXX微信里获取用户地理位置,有没有比较好的贴子,推荐下,谢了!

帅哥哟,离线,有人找我吗?
zhangjian222200
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1533 积分:10818 威望:0 精华:0 注册:2016/9/12 11:18:00
  发帖心情 Post By:2017/6/6 22:08:00 [只看该作者]

原来是经纬度前后颠倒填写造成错误的

Dim e As RequestEventArgs = args(0)                             '取得会员所在地
e.Resp
Dim wb As New weui

Dim shoujihao As String = e.Cookies("isj") '赋值手机号
Dim dr As DataRow = DataTables("会员资料").sqlFind("手机 = '" & shoujihao & "'")

Dim zdchengshi As String
Dim jingweidu As String = e.PlainText '如何将(longitude + "|" + latitude)分开及赋值?
Dim jingdu As Double = jingweidu.split("|")(0)
Dim weidu  As Double = jingweidu.split("|")(1)
'msgbox("经度:" & jingdu & "纬度:" & weidu)
Dim ur As String = "http://api.map.baidu.com/geocoder/v2/?ak=SzsmhchK2OSmg3Q94MGZ1TmRGyBw3SFl&output=json&location=" & weidu & "," & jingdu '前后位置改了
Dim hc As new HttpClient(ur)
Dim jo = JObject.Parse(hc.GetData)
output.show(jo.Tostring)
If jo("status") = 0 Then
msgbox("status值为0") '这里执行了
    If dr IsNot Nothing Then '已经登录 '因为这里不符合,跳转到else执行
        dr("定位_省份")= jo("result")("addressComponent")("province")
        dr("定位_城市")= jo("result")("addressComponent")("city")
        dr("定位_区县")= jo("result")("addressComponent")("district")
        msgbox(jo("result")("addressComponent")("province"))
        msgbox(jo("result")("addressComponent")("city"))
        msgbox(jo("result")("formatted_address"))
        msgbox(jo("result")("addressComponent")("district"))
        zdchengshi = dr("定位_城市")
        dr.save
    Else '没有登录
        zdchengshi = jo("result")("addressComponent")("city")
        msgbox(jo("result")("addressComponent")("city")) 
'这里准确地弹出我在的城市,但是,跳转链接后,首页的链接乱码如下:(index.htm代码最前面已经加了e.Response-Encoding = "utf-8"):
    End If
End If
e.WriteString(zdchengshi) '生成网页

js代码:
           function getLocation(){
               var options={
                   enableHighAccuracy:true, 
                   maximumAge:1000
               }
               if(navigator.geolocation){
                   //浏览器支持geolocation
                   navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
                   
               }else{
                   //浏览器不支持geolocation
               }
           }

           function onSuccess(position){
               //返回用户位置
               //经度
               var longitude =position.coords.longitude;
               //纬度
               var latitude = position.coords.latitude;
               //alert("成功"); 
               //alert(longitude + "   " + latitude);
               var result = sendAjaxText(longitude + "|" + latitude,"getplace.htm","",false);
if (result){
                //alert("ok1");
window.location.href= "/index.htm?zdchengshi=" + result;
}
               //alert("ok2");
           }
 
           //失败时
           function onError(error){
               switch(error.code){
                   case 1:
                   alert("位置服务被拒绝");
                   break;
                   case 2:
                   alert("暂时获取不到位置信息");
                   break;
                   case 3:
                   alert("获取信息超时");
                   break;
                   case 4:
                    alert("未知错误");
                   break;
               }
           }
[此贴子已经被作者于2017/6/6 22:19:47编辑过]

 回到顶部
总数 55 1 2 3 4 5 6 下一页