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.
+2
A:
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
Ken Redler
2010-08-19 01:39:33
I thought I was being as specific as I could. I do not want to create a web app unless I have no alternative. I have created a weather widget that does an xml request to a weather feed and then parses it...and from there displays weather information based on the parsed data. For the time being, the weather is being asked for based on a variable which holds a zip code. I want to change this to be a location based widget. Right now all I have is javascript and this runs all my code. I want to get the GPS cords from my own phone without having to go to some website...is this possible.
cameron213
2010-08-19 04:41:20
This is JavaScript. Nothing here is server side.
Ken Redler
2010-08-19 05:31:09
I was referring to the other answers that were left. I guess what I am creating would be considered a native app. I didnt understand the different between a web app and a native app and now I do. So I can use the W3C Geolocation API to get the gps coordinates for a native app?
cameron213
2010-08-19 05:58:27
If you're writing a native app -- i.e., using Cocoa, Objective C -- then you need to look into the Core Location framework. If what you're working with is JavaScript -- i.e., code that runs in Mobile Safari or a Webkit view, then the geolocation API (as above) is what you're looking for.
Ken Redler
2010-08-19 06:20:40