代码之家  ›  专栏  ›  技术社区  ›  HectorMac

iPhone网络应用程序能否获得GPS定位?

  •  17
  • HectorMac  · 技术社区  · 16 年前

    有没有一个简单的方法来设计一个网站,以方便 苹果手机 用户提供 GPS 坐标到现场?

    我想知道是否存在表单字段的命名约定,例如,允许用户以自动化方式输入。

    我正在考虑建立一个基于位置的网站,并希望为iPhone(和其他移动用户)量身定做。我意识到iPhone应用程序可以做到这一点,但我没有能力创建一个。

    4 回复  |  直到 11 年前
        1
  •  16
  •   Maciek    16 年前

    下面是一个关于如何从iPhone中读取位置的片段。看起来需要3.0:

     navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
    
     function foundLocation(position)
     {
       var lat = position.coords.latitude;
       var long = position.coords.longitude;
       alert('Found location: ' + lat + ', ' + long);
     }
     function noLocation()
     {
       alert('Could not find location');
     }
    

    见: http://mapscripting.com/how-to-use-geolocation-in-mobile-safari

    顺便说一句,如果你想在iPhone上使用网络代码,你可以尝试一些中间的解决方案,这些解决方案不会强迫你创建一个本地应用程序,而是允许你将你的网站包装在一个应用程序中,并访问GPS和其他本地功能。

        2
  •  4
  •   trapez    14 年前

    查看Jouni Erola导航下的应用程序发送位置。

    这是一个简单的应用程序,可以将iPhone的lat&lon发送到您的服务器。 只需输入您的服务器URL以接收作为http-get-methid的位置

        3
  •  1
  •   Charlie Bloom    15 年前

    我在没有任何编程的情况下就这样做了。你可以:

    1. 从iPhone商店下载iPhone应用程序“基本GPS”。
    2. 在twitter.com上创建一个帐户(如果你还没有)。
    3. 在twitter mail.com上启动一个电子邮件至twitter帐户。
    4. 在基本GPS设置中,使用Twittermail中的机密电子邮件地址。
    5. 在twitter.com/widgets上,单击“其他”获取用于在其他地方发布tweet的HTML代码。
    6. 把这个HTML代码放到你的主页上。
    7. 在基本的GPS中,你只需点击蓝色的“i”(开)按钮、“email”和“send”将你的位置发送到twittermail,twittermail会在twitter上发布它。Twitter会自动在你的主页上发布它。

    请参阅以下示例: http://CharlieBloom.com . 只有3条最新的(可定制的)tweet可见,点击“关注我在twitter上”以确定“我的位置…”和谷歌地图链接。职位在我发送后2-3分钟会在我的网站上更新。

    最好的问候, 查利布卢姆

        4
  •  1
  •   Michael Muller    11 年前

    是的,但是准确度很差。我刚构建了一个web表单,将GPS设置从watchposition()函数发布到我的数据库,然后映射结果。当沿着一条当地河流划水时,只有七根柱子中的两根是正确的。其余的都在河外,其中两个在一英里外!我正在寻找更好的解决方案。

    以下是我用来更新表单域的代码:

    <script type="text/javascript">
    function getGPSLocation()
    {
      if(navigator.geolocation)
      {
       navigator.geolocation.watchPosition(onGeoSuccess);
      } else {
       alert("Your browser or device doesn't support Geolocation");
      }
    }
    
    function onGeoSuccess(position) {
      document.getElementById("Latitude").value =  position.coords.latitude;
      document.getElementById("Longitude").value = position.coords.longitude;
    }
    </script>
    

    这就是表格。更新以满足您的需求。

    <form>
    <img src="spacer.gif" OnLoad="getGPSLocation();">
    <input type="Text" name="Latitude" id="Latitude" value="">
    <input type="Text" name="Longitude" id="Longitude" value="">
    </form>