Results 1 to 6 of 6

Thread: Current location on android devices

  1. #1
    Sencha User
    Join Date
    Apr 2013
    Posts
    45
    Answers
    3

    Default Current location on android devices

    Hi,

    In my Sencha app 2.1 i use the current location, so it work great on browser but when i package my application with Phonegap 2.2 for android devices, it doesn't work . Is there any method to know the current location whitout specifing (navigator) or using : useCurrentLocation: true" then "this.getMap()._geo.getLatitude();"



    Code:
    onDistTap: function () {
    
    
    
    
            var liste = this.getPlaces(); 
            var store = liste.getStore();
    
    
    
    
            store.each(function (record) {
    
    
    
    
                var lat = record.data.lat;
                var lng = record.data.lng;
    
    
                    navigator.geolocation.getCurrentPosition(function (position) {
    
    
                        // Distance calcule
    
    
    
    
                        
                        if (typeof(Number.prototype.toRad) === "undefined") {
                          Number.prototype.toRad = function() {
                            return this * Math.PI / 180;
                          }
                        }
    
    
    
    
    
    
    
    
                        var lat1 = lat ;
                        var lon1 = lng ;
    
    
    
    
                        var lat2 = position.coords.latitude;
                        var lon2 = position.coords.longitude;
    
    
    
    
                        var R = 6371; // km
                        var dLat = (lat2-lat1).toRad();
                        var dLon = (lon2-lon1).toRad();
                        var lat1 = lat1.toRad();
                        var lat2 = lat2.toRad();
    
    
    
    
                        var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                                Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
                        var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
                        var d = R * c;
    
    
    
    
                        console.log('Distance (km)');
                        console.log(d);
    
    
                        record.data.distance = d;                    liste.setData(record.data);
    
    
    
    
    
    
    
    
                    });
    
    
    
    
            });
    
    
    //store.setData(liste);
    store.sync();
    store.sort('distance', 'ASC');
    
    
    
    
          
        }
    Thanks in advance

  2. #2
    Sencha User
    Join Date
    Apr 2013
    Posts
    45
    Answers
    3

    Default

    Any suggestion

  3. #3
    Sencha User
    Join Date
    Jul 2011
    Location
    Pakistan
    Posts
    96
    Answers
    4

    Default

    do you enable location or gps settings in android settings ???

  4. #4
    Sencha User
    Join Date
    Apr 2013
    Posts
    45
    Answers
    3

    Default

    Yes it's enabled, i use a simulator

  5. #5

    Default

    how do i detect gps to alert message to the user that for use should enable the gps location on Android and iOS app.



    Quote Originally Posted by Dchar View Post
    Yes it's enabled, i use a simulator

  6. #6

    Default

    How do i detect GPS enable ON/Off in Android and iOS app, i would like to alert a message when GPS location is off to notify user to make it on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •