Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map.getMyLocation() method result with success AND error callback #309

Closed
davidruisinger opened this issue Nov 19, 2014 · 10 comments
Closed
Milestone

Comments

@davidruisinger
Copy link

I've this simple setup:

var opts = {
    enableHighAccuracy: true
};

var onSuccess = function(location) {
    console.log('success');
};

var onError = function(msg) {
    console.log('error');
};

map.getMyLocation(opts, onSuccess, onError);

And when the map.getMyLocation() method is called BOTH callbacks are executed and the console has both outputs...

@wf9a5m75
Copy link
Member

What error message is outputted?

@davidruisinger
Copy link
Author

I get two console outputs but both are 'null'. I'm running the app on a physical iOS device and the position is recognized and displayed with the "myPosition" icon on the map.

bildschirmfoto 2014-11-21 um 13 31 46

@davidruisinger
Copy link
Author

Here's what my code looks like. Because I'm using ionic, I'm firing $rootScope.$broadcast('initializeMap')
in my app.js within my $ionicPlatform.ready function.

angular.module('myApp.controllers', [])

.controller('MapCtrl', ['$scope', '$state', function($scope, $state) {
    // Method to initialize the map with the option set
    // And broadcast an event as soon as the map is ready
    $scope.$on('initializeMap', function() {
        $scope.initializeMap();
    });
    $scope.initializeMap = function() {
        var div = document.getElementById('map');

        // Define the start position the map will be initialized with
        const BERLIN = new plugin.google.maps.LatLng(52.52001,13.40495);

        var mapOptions = {
            'mapType': plugin.google.maps.MapTypeId.ROADMAP,
            'controls': {
                'compass': true,
                'myLocationButton': true,
                'indoorPicker': false,
                'zoom': false
            },
            'gestures': {
                'scroll': true,
                'tilt': true,
                'rotate': true,
                'zoom': true
            },
            'camera': {
                'latLng': BERLIN,
                'zoom': 10
            }
        };

        // Append the map plugin to the div
        $scope.map = plugin.google.maps.Map.getMap(div, mapOptions);

        // Event to fire as soon as the map is ready
        $scope.map.addEventListener(plugin.google.maps.event.MAP_READY, function(map) {
            // Broadcast an event to tell the child controller that the map is ready
            $scope.$broadcast('mapReady');

            // Remove the splashscreen when the map is ready
            navigator.splashscreen.hide();
        });
    };
}])

.controller('ShopsCtrl', ['$scope', function($scope) {

    $scope.$on('mapReady', function() {

        // Get the user position and panTo it if successful
        var opts = {
            enableHighAccuracy: true
        };

        var onSuccess = function(location) {
            console.log('success');
        };

        var onError = function(msg) {
            console.log(msg);
        };

        $scope.map.getMyLocation(opts, onSuccess, onError);
    });
}]);

@wf9a5m75
Copy link
Member

#312

@davidruisinger
Copy link
Author

Thanks, that explains all my "null" console.logs. But still both methods are called... If I add a console.log('error'); into the onError function I can see that both methods are called via the console.

bildschirmfoto 2014-11-21 um 18 43 54

@wf9a5m75
Copy link
Member

Just edit the www/googlemaps-cdv-plugin.js like this 1ec44f7

@davidruisinger
Copy link
Author

Thanks! The 'null' logs are gone. But I still have the issue, that the getMyLocation() method is fireing both, the success and the error callback. So my log no looks like this:

bildschirmfoto 2014-11-21 um 20 44 20

@ramoncarreras
Copy link

Same problem here.
The getMyLocation() method fires both callbacks (success and error).

@hirbod
Copy link
Contributor

hirbod commented Dec 10, 2014

getMyLocation is something buggy... I also faced a few problems. I recommend to use Cordovas Geolocation plugin for tracing your location and just to pass the results to google maps instead of relying on the interna function - till the bugs will be gone somedays - hopefully ;)

@ramoncarreras
Copy link

I will do it this way. Thanks @hirbod

@wf9a5m75 wf9a5m75 added this to the v1.2.5 milestone Feb 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants