Javascript 未定义Google标记管理器
我试图创建一个谷歌标记管理器,但得到的错误消息标记是没有定义的,我注释掉了导致问题的代码,我把它设置为用户点击地图并放置一个标记,我希望它能够做到这一点,自动出现在谷歌地图上使用谷歌标记管理器Javascript 未定义Google标记管理器,javascript,google-maps,google-maps-api-3,google-maps-markers,Javascript,Google Maps,Google Maps Api 3,Google Maps Markers,我试图创建一个谷歌标记管理器,但得到的错误消息标记是没有定义的,我注释掉了导致问题的代码,我把它设置为用户点击地图并放置一个标记,我希望它能够做到这一点,自动出现在谷歌地图上使用谷歌标记管理器 @{ ViewBag.Title = "Index"; } <h2>Index</h2> <div id="map_canvas" style="width:500px; height:500px;"></div> <script typ
@{
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>
@{
ViewBag.Title=“Index”;
}
指数
var映射;
var计数器;
var latlng;
变量位置地址;
var地理编码器;
函数初始化(){
geocoder=新的google.maps.geocoder();
latlng=新的google.maps.latlng(46.043830,14.488864);
变量myOptions={
缩放:16,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
计数器=0;
google.maps.event.addListener(映射,'click',函数(事件){
地图设置中心(事件设置);
地点标记(事件标记);
});
}
功能位置标记(位置){
var clickedLocation=new google.maps.LatLng(位置);
latlng=位置;
var marker=new google.maps.marker({
位置:位置,,
地图:地图
});
codeLatLng(位置、标记);
}
函数addLocationInfo(标记器){
var infoWindow=new google.maps.infoWindow({content:locationAddress,size:new google.maps.size(50,50)});
google.maps.event.addListener(标记,'click',函数(){
信息窗口。打开(地图、标记);
});
}
功能代码latlng(latlng,标记器){
if(地理编码器){
geocoder.geocode({'latLng':latLng},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
如果(结果[1]){
locationAddress=结果[1]。格式化的\u地址;
}
}否则{
locationAddress=“Neznan naslov”;
}
addLocationInfo(标记器);
});
}
}
////创建MarkerManager的新实例
//var mgr=新的MarkerManager(映射);
////创建标记数组
//var标记=[];
////循环以创建标记并将其添加到MarkerManager
//对于(变量i=0;i<50;i+=0.1){
//var标记=新的GMarker(新的GLatLng(59.0+i,13.80+i));
//标记器。推(标记器);
// }
////将数组添加到MarkerManager
//经理(标记);
////刷新MarkerManager以使标记显示在地图上
//经理刷新();
$(文档).ready(函数(){
初始化();
});
错误消息:未定义MarkerManager您混淆了谷歌地图API 2和API 3代码。
删除v=2参数或将其更改为v=3(例如,v=3.5) 更改此项: 传感器=truese 要么 传感器=真或传感器=假 删除API密钥,这仅适用于API 2
摆脱所有适用于API 2的GMap2、GLatLng类型的代码,并将其全部更改为API 3语法。我已经更新了我的代码,现在有一个新问题,很抱歉造成混淆。。我会尝试一下你的解决方案,看看会发生什么,愚蠢的我把API代码弄混了。尝试你的方式仍然会造成问题,我会坚持我在第一篇文章中所做的编码修改,等待有人能帮助/指导我,“你的方式”仍然使用与API 3不兼容的API 2代码。您正在调用Marker Manager所需的JS文件吗?那么如何将其更改为API 3?这对我来说有点新鲜。该死的,我没有JS文件,我可以从哪里下载或者从外部调用它?你可以从这里开始: