Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked March 16th 2010 by Tim Haslam
  • iphone
  • location
  • map
0 Comments

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);
    
    
    });
    
    — answered March 16th 2010 by Rob Edgell
    permalink
    0 Comments
  • 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

    — answered March 16th 2010 by Rob Edgell
    permalink
    0 Comments
  • Code is not valid for 1.0.

    Kitchen Sink has a good example for this in the Geolocation examples.

    — answered March 16th 2010 by Jeff Haynie
    permalink
    0 Comments
  • 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?

    — answered March 16th 2010 by Tim Haslam
    permalink
    0 Comments
  • 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?

    — answered March 16th 2010 by Tim Haslam
    permalink
    0 Comments
  • Tim,

    Try creating your map view in your callback of getCurrentPosition.

    — answered March 16th 2010 by Rob Edgell
    permalink
    0 Comments
  • Also, what you pasted will not work if you are using Titanium 1.0.

    — answered March 16th 2010 by Rob Edgell
    permalink
    0 Comments
  • 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?

    — answered March 16th 2010 by Tim Haslam
    permalink
    0 Comments
  • 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…

    — answered March 16th 2010 by Tim Haslam
    permalink
    0 Comments
  • This is where your problem is Titanium.Geolocation.distanceFilter = 10;

    Comment it and you should be fine.

    — answered July 3rd 2012 by Samuel Lopez
    permalink
    0 Comments
  • Emulator can not show the current location. So you have to run this code in a device.

    — answered April 5th 2014 by Azmal Dalim
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.