admin管理员组文章数量:1391943
I'm assuming this is straight forward, just not having any luck with it.
I have the following functions
function init(myPoint) {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(myPoint, -122.39031314844),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
function start() {
google.maps.event.addDomListener(window, 'load', init(37.2342));
}
If I remove the param and just hardcode myPoint everything works. However in its current state it does not work. Can someone explain to me what I'm doing wrong.
Thanks
I'm assuming this is straight forward, just not having any luck with it.
I have the following functions
function init(myPoint) {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(myPoint, -122.39031314844),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
function start() {
google.maps.event.addDomListener(window, 'load', init(37.2342));
}
If I remove the param and just hardcode myPoint everything works. However in its current state it does not work. Can someone explain to me what I'm doing wrong.
Thanks
Share Improve this question asked Nov 24, 2010 at 9:31 SteveSteve 21.5k24 gold badges72 silver badges92 bronze badges 1- EXACTLY the problem I was having! – CodyBugstein Commented Jul 20, 2014 at 22:51
1 Answer
Reset to default 9Your function is not called on window load; it is called upon code execution. instead of init(37.2342)
you should use function(){init(37.2342);}
with addDomListener
:
google.maps.event.addDomListener(window, 'load', function () { init(37.2342); });
本文标签: javascriptPassing parameters to function that creates a google map doesn39t workStack Overflow
版权声明:本文标题:javascript - Passing parameters to function that creates a google map doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744687498a2619792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论