hello,
I have a problem with the centering and zooming of a google map that displays directions.
in my app i have a page with a panel (it has been built within a grid) and some buttons.
In my panel i added a google map component and i added to the app a java script asset:
codevar directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
}
function displayDirections(sourceAddress, destinationAddress, waypoint){
var myOptions = {
zoom: 6,
center: new google.maps.LatLng(39.4939, 16.3846),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($('div[dsid="googlemap_strade"]').get(0), myOptions);
Code: Select all
var request = {
origin: sourceAddress,
destination: destinationAddress,
waypoints: [{
location: '"' + waypoint + '"',
stopover: false
}],
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
function getDirections() {
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Si è verificato un prolema. Response status: " + status);
}
});
}
directionsDisplay.setMap(map);
getDirections();
/code on the page load event i added code initialize() /code
on one of the buttons in the page where i want to show the map, on a click events i
1) open the panel running the js (codewindow.awesomeMenu_mapStrade2.panel("open");/code
2) i run the JS: codevar sourceAddress = "Cosenza"
var destinationAddress = "Castrovillari, CS"
var waypoint = "Cassano allo ionio, CS"
displayDirections(sourceAddress, destinationAddress, waypoint);/code
the problem is that the first time i click the button my panel opens correctly but it displays a map that is not centered in the right way and the zoom is to low
while if i click again to the same button i get the map i want:
how can i get the right map on the first button click?