1. #1
    Sencha Premium Member IAmCoder's Avatar
    Join Date
    Mar 2012
    Posts
    33
    Vote Rating
    1
    IAmCoder is on a distinguished road

      0  

    Default Plotting GPS coordinates on a map

    Plotting GPS coordinates on a map


    I made a simple GPS tracking app that draws a line to the current location and moves a marker each time the location changes.

    BTek-GPS-Trakker.jpg

    Code:
    cordova.exec(
        function SuccessHandler (result) {
     
            // Center the map
            me.getComponent('map').setMapCenter({ atitude: result.latitude, longitude: result.longitude});
     
            if (MyApp.app.LastLatitude !== null && MyApp.app.LastLatitude !== '')
            {
                // Add a line to the map
                var flightPlanCoordinates = [
                    new google.maps.LatLng(MyApp.app.LastLatitude, MyApp.app.LastLongitude),
                    new google.maps.LatLng(result.latitude, result.longitude)
                ];
                var flightPath = new google.maps.Polyline({
                    path: flightPlanCoordinates,
                    strokeColor: "#4682b4",
                    strokeOpacity: 0.8,
                    strokeWeight: 2
                });
                flightPath.setMap(me.getComponent('map').getMap());
     
                // Remove the old marker
                MyApp.app.Marker.setMap(null);
            }
     
            // Add a new marker
            var position = new google.maps.LatLng (result.latitude, result.longitude);
            MyApp.app.Marker = new google.maps.Marker({
                position: position,
                title: result.latitude + ', ' + result.longitude,
                icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
                map: me.getComponent('map').getMap()
            });
            MyApp.app.Marker.setMap(me.getComponent('map').getMap());
     
            MyApp.app.LastLatitude = result.latitude;
            MyApp.app.LastLongitude = result.longitude;
     
            },
        function ErrorHandler (error) {
            alert("Native call failed: " + error);
        },
        'BTekGPSPlugin', '', []);
    }, this);
    The source is on GitHub and the calls that get the coordinates from native code are detailed here: http://www.btek.com.au/tracking-move...ative-process/. I used a custom GPS class because the coordinates will need to be pre-processed by existing business logic.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Thanks for sharing your code.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2013
    Posts
    7
    Vote Rating
    1
    khooten is on a distinguished road

      0  

    Default


    Have you had any problems with the accuracy of readings from GPS?

Thread Participants: 2