0

場所の地図にマーカーを付けようとしていますが、オプションでエラーが発生しますが、地図を単独で読み込むと正常に動作します

hier は私のコードです

<script type="text/javascript">
    //var map;
    function initialize() {  if (GBrowserIsCompatible()) {
            var lat = parseFloat(document.getElementById("FormView1_LatitudeLabel").textContent);
            var lng = parseFloat(document.getElementById("FormView1_LongitudeLabel").textContent);


            // Creating a map

                    // Creating a LatLng object containing the coordinate for the center of the map  
                    var latlng = new google.maps.LatLng(lat, lng);
                    // Creating an object literal containing the properties we want to pass to the map  
                    var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                    };
                    // Calling the constructor, thereby initializing the map  
                    var map = new google.maps.Map(document.getElementById('map'), options);

                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(lat, lng),
                        map: map,
                        title: 'My workplace',
                        clickable: false,
                        icon: 'img/factory.png'
                    });
                }
  }   
 </script>
4

3 に答える 3

2

GBrowserIsCompatible() は V2 メソッドですが、残りのコードは V3 です。単一の API バージョンを決定する必要があります。

于 2012-09-18T13:53:36.767 に答える
0

ここの最後の項目の末尾のコンマにより、Internet Explorer でエラーが発生します。

var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                    };

次のようにする必要があります。

var options = {
                        zoom: 7,
                        center: latlng,
                        mapTypeId: google.maps.MapTypeId.ROADMAP
                    };
于 2012-09-18T14:39:29.727 に答える
0

あなたが何を望んでいるかはよくわかりませんが、

marker.setMap(map);

マップ上にマーカーが表示されます。

map.panTo(marker.getPosition())

マップをマーカーにパンできます。

詳細については、 https://developers.google.com/maps/documentation/javascript/reference#Markerを参照してください。

于 2012-09-18T13:47:02.280 に答える