ASP.NET MVC 4を使用していて、次のようなDIVがあります。
<div id="map_canvas" style="width: 500px; height: 400px;" onload="mapAddress();"></div>
次に、JavaScriptファイル(私が確認したものがロードされている)には、次のmapAddress
関数があります。
function mapAddress() {
//In this case it gets the address from an element on the page, but obviously you could just pass it to the method instead
var address = $("#Address").val();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myLatLng = results[0].geometry.location.LatLng;
var mapOptions = {
center: myLatLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: $("#Name").val() + " Location"
});
}
else {
alert("The location of the event could not be mapped because: " + status);
}
});
}
しかし、何らかの理由でそれは呼ばれていません。onload
イベントを誤解しましたか?
皆さんありがとう!