最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Access iPhone GPS coordinates - Stack Overflow

programmeradmin3浏览0评论

Basically what I am trying to do is get access to the gps coordinates on the iphone 4. I'm not creating any type of web app. I can't find too much other than the geolocation api, but that seems to be geared toward creating web apps. Is there a javascript function that I can call from the phone itself that will return its own gps coordinates. Bascially what I'm working on is a weather widget that creates an xmlrequest and parses that returned data. The widget works fine for a specific zip code. however, I am wanting to see if I can get this running based on gps. The website which returns the xml response also allows gps coords. Just looking for the best way to fetch the coords and pass them to this site.

Basically what I am trying to do is get access to the gps coordinates on the iphone 4. I'm not creating any type of web app. I can't find too much other than the geolocation api, but that seems to be geared toward creating web apps. Is there a javascript function that I can call from the phone itself that will return its own gps coordinates. Bascially what I'm working on is a weather widget that creates an xmlrequest and parses that returned data. The widget works fine for a specific zip code. however, I am wanting to see if I can get this running based on gps. The website which returns the xml response also allows gps coords. Just looking for the best way to fetch the coords and pass them to this site.

Share Improve this question edited Aug 19, 2010 at 1:40 RedBlueThing 42.5k17 gold badges98 silver badges122 bronze badges asked Aug 19, 2010 at 1:19 cameron213cameron213 1692 gold badges5 silver badges12 bronze badges 3
  • create a simple app for the iphone with location manager – alecnash Commented Aug 19, 2010 at 1:27
  • @alecnash Sounds like he is trying to do this from a web app, not a native app. – RedBlueThing Commented Aug 19, 2010 at 1:40
  • The question is not super clear. @cameron213, are you trying to get the coordinates from your web page which users will see in Mobile Safari? Or a Cocoa iPhone app? The W3C Geolocation API and CoreLocation are the respective answers, I believe. – npdoty Commented Aug 19, 2010 at 2:48
Add a ment  | 

1 Answer 1

Reset to default 5

Try something like this:

navigator.geolocation.getCurrentPosition( function(loc){
    var lat = loc.coords.latitude;
    var lon = loc.coords.longitude;
    doSomethingWith( lat, lon ); // your function    
});

References: Mobile Safari Documentation

发布评论

评论列表(0)

  1. 暂无评论