1

Google マップが表示されません。問題は緯度と経度のデータ型にあると思います。コードは次のとおりです。緯度経度のハードコードされた値が提供されている場合、すべての関数は正常に機能します。

function initialize(a, b, zoom) {
    alert('init called  ' + "lat: " + typeof a + "long: " + typeof b + "zoom: " + typeof zoom);
    //here lat long are string and zoom is number 

    //var zoom =parseInt(zoom);
    var a = parseFloat(a);
    var b = parseFloat(b);
    alert('init called  ' + "lat: " + typeof a + "long: " + typeof b + "zoom: " + typeof zoom);

    //here lat oang and zoom all are number
    var centerLoc = new google.maps.LatLng(a, b);

    var mapProp = {
        center: centerLoc,
        zoom: zoom,
        //   mapTypeId:google.maps.MapTypeId.ROADMAP,
        mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
    marker = new google.maps.Marker({
        position: centerLoc,
        title: 'Click to zoom'
    });
    google.maps.event.addListener(marker, 'click', function () {
        map.setZoom(map.getZoom() + 1);
        map.setCenter(marker.getPosition());
    });
    marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);

</script>

ここにhtmlがあります:

<html>
<body>
<div id="googleMap" style="width:1000px;height:500px;"></div>
</body>
</html>
4

1 に答える 1