Can iPhone web apps get GPS position?

前端 未结 4 1391
情深已故
情深已故 2021-01-30 14:49

Is there an easy way to design a website to facilitate an iphone user providing gps coordinates to the site?

I am wondering if there m

4条回答
  •  故里飘歌
    2021-01-30 15:33

    Here's a snippet on how to read location from the iPhone. Looks like it requires 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');
     }
    

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

    By the way, if you want to use web code on the iPhone, there are a couple middle-ground solutions you could try that don't force you to create a native app but allow you to wrap your site in an app and get access to GPS and other native features.

    • PhoneGap: http://phonegap.com/
    • Appcelerator: http://www.appcelerator.com/products/titanium-mobile/

提交回复
热议问题