5
Mam pewne problemy z mapami google geokodowania api.Angular Google map geokodowanie callback
Używam kątowe Mapy Google i próbuje Geokodując adres z funkcji wywołania zwrotnego:
.controller('myCtrl', ['$scope', '$rootScope', 'uiGmapGoogleMapApi', function ($scope, $rootScope, uiGmapGoogleMapApi) {
// To be set by previous step
$rootScope.chosenTown = "Roma"
// geocode the given address
var geocodeAddress = function(address, callback) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
callback(results[0].geometry.location);
} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
};
// google maps is ready
uiGmapGoogleMapApi.then(function(maps) {
// geocode chosen town
geocodeAddress($rootScope.chosenTown, function(latLng){
console.log("1 " + latLng.lat())
console.log("2 " + latLng.lng())
$scope.map = { center: { latitude: latLng.lat(), longitude: latLng.lng() }, zoom: 12, bounds: {}};
});
});
}])
I kod html:
<div class="col-lg-5 finalStepMap">
<ui-gmap-google-map center='map.center' zoom='map.zoom' draggable="true" options="options" bounds="map.bounds">
<ui-gmap-markers models="markers" coords="'self'" options="'options'"></ui-gmap-markers>
</ui-gmap-google-map>
</div>
Mapa nie jest wyświetlany.
Jednak jeśli zadzwonię:
$scope.map = { center: { latitude: 10, longitude: 40}, zoom: 12, bounds: {}};
});
Przy stałym lat i LNG na zewnątrz funkcji zwrotnej, wszystko działa bez zarzutu.
Jakaś wskazówka?
Dzięki za cenną pomoc :)