Getting a users Current Location
Hey,
I want to be able to have a view where it will show the users current location. I have tried using the Titanium.Geolocation.getCurrentPosition and I also tried Titanium.Geolocation.watchPosition - but they just bring up a blank, black screen which makes me think I am doing something wrong with my code:
http://pastie.org/870968
Thanks in advance - TH
11 Answers
-
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; // // SET DISTANCE FILTER. THIS DICTATES HOW OFTEN AN EVENT FIRES BASED ON THE DISTANCE THE DEVICE MOVES // THIS VALUE IS IN METERS // Titanium.Geolocation.distanceFilter = 10; // // GET CURRENT POSITION - THIS FIRES ONCE // Titanium.Geolocation.getCurrentPosition(function(e) { if (e.error) { alert('HFL cannot get your current location'); return; } var longitude = e.coords.longitude; var latitude = e.coords.latitude; var altitude = e.coords.altitude; var heading = e.coords.heading; var accuracy = e.coords.accuracy; var speed = e.coords.speed; var timestamp = e.coords.timestamp; var altitudeAccuracy = e.coords.altitudeAccuracy; // //CREATE MAP VIEW // var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: {latitude: latitude, longitude: longitude, latitudeDelta:0.01, longitudeDelta:0.01}, animate:true, regionFit:true, userLocation:true, annotations:[annotation] }); win.add(mapview); });
-
There are several web casts on the Appcelerator site about converting your application. 1.0 does away with the need to use any HTML. I would check out http://www.vimeo.com/9960118
-
Code is not valid for 1.0.
Kitchen Sink has a good example for this in the Geolocation examples.
-
Hey Jeff - I downloaded the new Kitchen Sink but it wouldn't launch in my simulator - I tried this though
http://pastie.org/872541 and it just gives me a blank screen. Any suggestions?
-
Hey Jeff - I downloaded the new Kitchen Sink but it wouldn't launch in my simulator - I tried this though
http://pastie.org/872541 and it just gives me a blank screen. Any suggestions?
-
Tim,
Try creating your map view in your callback of getCurrentPosition.
-
Also, what you pasted will not work if you are using Titanium 1.0.
-
okay - thanks for your help Rob - it looks like I was trying to insert 1.0 code into my app which was 0.8.1 - I updated it in the Edit view but how do I update all my code to be 1.0?
-
Thanks Rob - looks like I will just be starting from scratch again. Good thing I haven't done too much development on this app so far. I feel bad for those who have done a lot of work and then have to update their stuff…
-
This is where your problem is Titanium.Geolocation.distanceFilter = 10;
Comment it and you should be fine.
-
Emulator can not show the current location. So you have to run this code in a device.