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