dongmo2324 2016-10-20 10:21
浏览 24

我怎么知道用户的位置

I try to detect the exact location of user and specially the street if i can.

I tried that using the IP but this didn't work for me because it didn't give the exact location example for what i want is Lebanon Beirut Azarieh or Lebanon Beirut ABC Achrafieh and than i want to store this location in MYSQL database table using PHP.

i tried this code here this code give a good location in Firefox on Localhost

but Online on Firefox and Google chrome give me that Your Location: Not Available

also it didn't work on phone browser iPhone and android (safari,chrome,...)

the idea is a user in the company want to use the website on his phone a special page on the website when he use it i want to take here exact location with the street and store this in database

  • 写回答

2条回答 默认 最新

  • dongqiang8683 2016-10-20 10:26
    关注

    You can use a flag, enableHighAccuracy:true

    Here's an example code:

    $(document).ready(function($){
      if (navigator.geolocation){
          navigator.geolocation.getCurrentPosition(function(position){
            latitude = position.coords.latitude;
            longitude = position.coords.longitude;
              //alert('latitude: '+latitude+' longitude: '+longitude);
          }, function(error) {
              alert('Error occurred. Error code: ' + error.code);
          },{timeout:20000,enableHighAccuracy: true});
      }
      else{
        alert('no geolocation support');
      }
    });
    

    And I also want to quote that enableHighAccuracy depends from device to device.

    reference here

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?