0

Could really do with some help, I'm trying to push an alert on an android phone with the help of sencha when a user is near a certain set point of interest.

In my view I have a map

{
        xtype: 'map',
        id: 'mapOne',
        cls: 'center',
        flex: 1,
        width: '100%',

        mapOptions : {
            mapTypeControl : false,
            navigationControl : true,
            streetViewControl : false,
            backgroundColor: 'transparent',
            disableDoubleClickZoom: true,
            zoom: 10,
            draggable: true,
            keyboardShortcuts: true,
            scrollwheel: false,
            enableHighAccuracy: true
        },


        listeners : {
            maprender : function(comp, map){

                var currentMarker = new google.maps.Marker({
                position: new google.maps.LatLng(setlat,setlon),
                //title : 'Sencha HQ',
                map: map,
                icon: image
                });



                setTimeout( function(){map.panTo (new google.maps.LatLng(markerlat, markerlong));} , 1);


            }
 }

In my controller I set the following before my map is rendered

 var poi = new google.maps.LatLng(markerlat, markerlong);

Then in my controller im initalizing a geolocation object as follows

 var geo = Ext.create('Ext.util.Geolocation', {
autoUpdate: true,
frequency :3000,//every 3 seconds
listeners: {
    locationupdate: function(geo) {

        var curlat = geo.position.coords.latitude;
         var curlong = geo.position.coords.longitude;
         console.log('New GEO CURRENT: ' + curlat + ' ' + curlong);
         var me = new google.maps.LatLng(curlat, curlong);

        if (me == poi){
            alert("poi found");
        }

    },
    locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
        if(bTimeout){
            alert('Timeout occurred.');
        } else {
            alert('Error occurred.');
        }
    }
}

});

I have also set a geomarker to see if I being detected anyway near the poi.

 GeoMarker = new GeolocationMarker(mapOne);

It shows my GeoMarker directly on top of the marker with no alert. I tried a few different similar things with no success like the following....

 if (GeoMarker == poi){
            alert("poi found");
        }

I know my process is wrong here in both cases as my position won't be exactly the same as the poi but I can't figure out how to set the proper proximity of the current position to to alert. I'm finding it hard to find any documentation that shows how to successfully implement something similar with respect to alerting at a poi. Any help or links to documentation that might help would be greatly appreciated.

Thanks in advance

hotshots
  • 115
  • 4
  • 16

1 Answers1

0

I first got successful results through using 'if' statements to check if the difference between the latitude and longitude values of both points were less than a set variable. But I thought there must be a more efficient method of implementing this through some form of radius around the current location.

Finally came across this thread.... Calculate distance between two points in google maps V3 and as it suggested in one of the answers I used the following with success......

 google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB); 

to check if the distance between both points was less than my desired distance. Hope this helps someone in the future.

Any information from anyone to alternative methods for carry out the same would be welcomed though.

Community
  • 1
  • 1
hotshots
  • 115
  • 4
  • 16