I have this map:
.... class Maps ....
Maps.prototype.initialize = function (x, y) {
var latitude = x;
var longitude = y;
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(latitude, longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'Click to zoom'
});
};
Maps.prototype.changePosition = function (x, y) {
var latitude = x;
var longitude = y;
var map = new google.maps.LatLng(latitude, longitude);
marker.setPosition(map);
}
....
then:
var maps = new Maps();
var marker = maps.initialize(x, y);
window.setTimeout(function() {
maps.changePosition(x, y));
}, 3000);
the initialize method works, and renders the map and the marker
but the second one doesn’t work, doesn’t know what setPosition is
any ideas on this issue?
There are different issues.
the first one, which will prevent the code from executing: your iinitialize-function doesn’t have a return-value, so your
maps-variable is undefined and didn’t have a methodchangePosition.Later: the changePosition has to arguments ,
zandy, but inside the function you access the variablesxandyHowever, I don’t see any code that modifies
xandy, so even when the code would work it doesn’t have any visible effect.