I found my self in a problematic situation. I need to show a centered map, and a marker using Geolocacion. Currently, i'm using angular and the ngmaps directive. Btw: I'm programming in PHP with Laravel, so the views, are something.blade.php
Here's my code
//controller.js
var currentLatitude = 0;
var currentLongitude = 0;
var geo_url = "http://ift.tt/2hM9kbb";
$.ajax({
type : 'POST',
url : geo_url,
contentType : 'application/json',
success : function(data) {
$scope.marker.position[0] = data.location.lat;
$scope.marker.position[1] = data.location.lng;
$scope.map.center[0] = data.location.lat;
$scope.map.center[1] = data.location.lng;
},
error : function() {
console.log("No es posible determinar tu ubicación");
$scope.marker.position[0] = -33.452021493;
$scope.marker.position[1] = -70.617061246;
}
});
// Draw the map
$scope.map = {
center : [ currentLatitude, currentLongitude],
options : function() {
return {
streetViewControl : false,
scrollwheel : true,
fullscreenControl : false,
zoom : 13,
}
},
events : {
mousemove : function(e, map) {
google.maps.event
.trigger(map, 'resize');
}
}
};
$scope.marker = {
position : [ 0, 0 ],
decimals : 10,
options : function() {
return {
draggable : true
};
}
}
Now, the view:
// This is my view.blade.php
<map ng-transclude class="google-map" center="map.center"
options="map.options" events="map.events" ng-model="mapElement"
ng-init="mapElement=true">
<marker position="marker.position" decimals="marker.decimals"
options="marker.options"></marker>
</map>
The Main problem: The map is shown correctly, and the marker as well, but, the map is not centered where is supposed to be centered, which is in this case, the marker coordinate. So what I'm understanding here, is that my map should be centered and markered in the same coordinate, but what it happens is the marker is locataed where it should be, but not the map. Am I missing something? Any help is appriciated. Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire