I am trying to get my center location to change on my google map based on a button click. I have more functionality to add later, but I can't get this basic update to work. I have a default value that loads on page load. The button should set a new location, but I see that it does update but then is quickly overridden by the default value because the page loads again.
I am new to google maps, and I am just trying to figure out how to load and interact with the map correctly.
Here is my code:
<script src="http://ift.tt/13qgtmt"></script>
<script>
var deanLat = 43.0843816;
var deanLong = -89.5302394;
var deanAddress = '1277 deming way, madison wi';
var stmaryLat = 43.0592730;
var stmaryLong = -89.4015130;
var stmaryAddress = '700 S Park St, Madison, WI 53715';
$("#FindDean").click(function() {
refreshMap(deanLat, deanLong);
});
function alertme(message) {
alert (message);
}
function refreshMap(ilat,ilong) {
ilat = typeof ilat !== 'undefined' ? ilat : stmaryLat;
ilong = typeof ilong !== 'undefined' ? ilong : stmaryLong;
alertme(ilat);
var mapOptions = {
zoom: 16,
center: new google.maps.LatLng(ilat, ilong)
};
gmap = new google.maps.Map(document.getElementById('mapholder'),
mapOptions);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://ift.tt/1lrRXYd' +
'&signed_in=true&callback=refreshMap';
document.body.appendChild(script);
}
window.onload = loadScript;
Aucun commentaire :
Enregistrer un commentaire