0

I'm using ng-map, and I'm using navigator.geolocation.getCurrentPosition to get the user's current location, however in Ffx, the success callback doesn't seem to get called. When I add a breakpoint inside the callback function, it is never hit (it works in other browsers I've tested). Here's my code:

                    var options = {
                    };

                    navigator.geolocation.getCurrentPosition(
                        function (pos) {
                            var myLatLng = new google.maps.LatLng(parseFloat(pos.coords.latitude), parseFloat(pos.coords.longitude));
                            map.setCenter(myLatLng);
                        }, 
                        function (error) { return false; },
                        options);

What I've tried:

  • Checking if the error callback is being called (it never is, I can't see any errors)
  • Adding a short (e.g. 5000ms) timeout to the options
  • Setting enableHighAccuracy to be explicitly false in the options
  • Explicitly specifying 'success' and 'error' function and calling them, instead of adding the functions 'inline' (not that this should make any difference, and no, it didn't!)
  • Using navigator.geolocation.watchPosition instead of getCurrentPosition
  • I'm using the ng-map angular directive for the maps, and I've tried removing 'position' from my custom marker that displays the current location, to try to make sure there's nothing interfering, or intercepting the callback.

Any fresh ideas or suggestions of anything I can try are very welcome!

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206

1 Answers1

0

I found out that setting:

position="current-location"

on the <custom-marker> that I'm using to display the current location with ng-map actually does call navigator.geolocation.getCurrentPosition and was interfering with my own call to getCurrentPosition. I now use the following as the position in my <custom-marker>:

position="{{mapsCtrl.userLat + ',' + mapsCtrl.userLng}}"

... and I set it like this:

navigator.geolocation.getCurrentPosition(
    function (pos) {
        var myLatLng = new google.maps.LatLng(parseFloat(pos.coords.latitude), parseFloat(pos.coords.longitude));
        this.setCurrentLocationMarker(myLatLng);
        map.setCenter(myLatLng);
    },
    function (error) { return false; });

    setCurrentLocationMarker(latLng) {
        this.userLat = latLng.lat();
        this.userLng = latLng.lng();
        this.$scope.$apply();
    }
Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206