dylanfprice / angular-gm

AngularJS Google Maps Directives
MIT License
198 stars 47 forks source link

GeoLocation support #50

Closed gauravsaini03-zz closed 10 years ago

gauravsaini03-zz commented 10 years ago

Hello,

I am unable to re-create map, after getting the gelocation of user, with new Lat and Long. I searched but did not see any way to work with geolocation.

Thanks Gaurav

AmbikaFR commented 10 years ago

I have just used this solution : You can use a .run function in your app.js. You can get your map this way in your run function :

var gmapPromise = angulargmContainer.getMapPromise('yourMapId');

gmapPromise.then(function(gmap) {
        gmap.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
    }
    );

    navigator.geolocation.watchPosition(function(position) {
        gmap.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
    });
});

})

Where "yourMapId" is your CSS Id for your gmap.

gauravsaini03-zz commented 10 years ago

Thanks AmbikaFR, I actually was able to resolved the problem. onSuccess of geolocation I passed new lat and long and applied it.

var onSuccess = function(position) {
    $scope.map.center = {
         latitude: position.coords.latitude,
         longitude: position.coords.longitude
    };
        $scope.$apply();
}