0

即時嘗試創建谷歌標記管理器,但得到的錯誤消息標記未定義,ive註釋掉了導致問題的代碼,我已設置爲用戶單擊地圖並放置一個標記,我希望它能夠做到這一點使用Google標記管理谷歌標記管理器沒有定義

自動出現在谷歌地圖上
@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<div id="map_canvas" style="width:500px; height:500px;"></div> 

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"> 

</script> 


    <script type="text/javascript"> 

     var map; 
     var counter; 
     var latlng; 
     var locationAddress; 
     var geocoder; 
     function initialize() { 
      geocoder = new google.maps.Geocoder(); 
      latlng = new google.maps.LatLng(46.043830, 14.488864); 
      var myOptions = { 
       zoom: 16, 
       center: latlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
      counter = 0; 

      google.maps.event.addListener(map, 'click', function (event) { 
       map.setCenter(event.latlng); 
       placeMarker(event.latLng); 

      }); 


     } 

     function placeMarker(location) { 
      var clickedLocation = new google.maps.LatLng(location); 
      latlng = location; 
      var marker = new google.maps.Marker({ 
       position: location, 
       map: map 
      }); 
      codeLatLng(location, marker); 
     } 

     function addLocationInfo(marker) { 
      var infoWindow = new google.maps.InfoWindow({ content: locationAddress, size: new google.maps.Size(50, 50) }); 
      google.maps.event.addListener(marker, 'click', function() { 
       infoWindow.open(map, marker); 
      }); 
     } 

     function codeLatLng(latlng, marker) { 
      if (geocoder) { 
       geocoder.geocode({ 'latLng': latlng }, function (results, status) { 
        if (status == google.maps.GeocoderStatus.OK) { 
         if (results[1]) { 
          locationAddress = results[1].formatted_address; 
         } 
        } else { 
         locationAddress = "Neznan naslov"; 
        } 
        addLocationInfo(marker); 
       }); 
      } 
     } 

//  // Create a new instance of the MarkerManager 
//  var mgr = new MarkerManager(map); 
//  // Create marker array 
//  var markers = []; 
//  // Loop to create markers and adding them to the MarkerManager 
//  for (var i = 0; i < 50; i += 0.1) { 
//   var marker = new GMarker(new GLatLng(59.0 + i, 13.80 + i)); 
//   markers.push(marker); 
//  } 
//  // Add the array to the MarkerManager 
//  mgr.addMarkers(markers); 
//  // Refresh the MarkerManager to make the markers appear on the map 
//  mgr.refresh(); 

     $(document).ready(function() { 
      initialize(); 
     }); 

    </script> 

錯誤消息: MarkerManager沒有定義

回答

2

你混淆了谷歌地圖API 2和API 3代碼。
刪除v = 2參數或將其更改爲v = 3(或v = 3.5)。

更改此: 傳感器= truese 要麼 傳感器= true或傳感器=假

取出API密鑰,這是隻需要在API 2.

擺脫所有的GMap2,的GLatLng的用於API 2的代碼類型並將其全部更改爲API 3語法。

+0

我已經更新了我的代碼,現在我有一個新問題,對於混淆抱歉..我會給你的解決方案去看看會發生什麼,愚蠢的我混合API代碼。 – MJCoder

+0

嘗試你的方式仍然會造成問題,我會堅持我在我的第一篇文章中所做的編碼修正,並等到有人可以幫助/指導我 – MJCoder

+0

'你的方式'仍然使用與API不兼容的API 2代碼3.您是否在標記管理器要求的JS文件中調用? – duncan