使用Ajax和jQuery从json向Google地图添加标记的问题
我试图使用以下代码从json文件中添加一些标记,但它不起作用! 在这里,您可以看到正在运行的使用Ajax和jQuery从json向Google地图添加标记的问题,jquery,ajax,google-maps,google-maps-api-3,google-maps-markers,Jquery,Ajax,Google Maps,Google Maps Api 3,Google Maps Markers,我试图使用以下代码从json文件中添加一些标记,但它不起作用! 在这里,您可以看到正在运行的 var映射; $(文档).ready(函数(){ var latlng=new google.maps.latlng(11.818965123.727169); 变量myOptions={ 缩放:0, 中心:拉特林, disableDefaultUI:true, scaleControl:对, 动物控制:对, ZoomControl选项:{ 样式:google.maps.ZoomControlStyle
var映射;
$(文档).ready(函数(){
var latlng=new google.maps.latlng(11.818965123.727169);
变量myOptions={
缩放:0,
中心:拉特林,
disableDefaultUI:true,
scaleControl:对,
动物控制:对,
ZoomControl选项:{
样式:google.maps.ZoomControlStyle.SMALL
},
mapTypeControl:true,
DragTableCursor:“移动”,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
//setOptions({styles:styles});//未定义样式
$.ajax({
类型:“POST”,
网址:'http://supermobile.dk/html5/webApp.GMAP/json/demo.txt',
数据类型:“json”,
成功:函数(数据){
位置。长度=0;
对于(p=0;p
你能告诉我我做错了什么吗?谢谢
更新:
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.google.com/maps/api/js?sensor=false&dummy=.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<style>
#map_canvas {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<script>
var map;
$(document).ready(function () {
var latlng = new google.maps.LatLng(11.818965,123.727169);
var myOptions = {
zoom: 0,
center: latlng,
disableDefaultUI: true,
scaleControl: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
mapTypeControl:true,
draggableCursor: 'move',
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
$.ajax({
type: "POST",
url: 'data.json',
dataType: 'json',
success: function(data){
locations.length = 0;
for (p = 0; p < data.length; p++) {
locations.push(Array(data[p].latitude,data[p].longitude));
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data[p].latitude,data[p].longitude),
map: map,
title:"marker "+p
});
}
}
});
});
</script>
</body>
</html>
#地图画布{
宽度:100%;
高度:400px;
}
var映射;
$(文档).ready(函数(){
var latlng=new google.maps.latlng(11.818965123.727169);
变量myOptions={
缩放:0,
中心:拉特林,
disableDefaultUI:true,
scaleControl:对,
动物控制:对,
ZoomControl选项:{
样式:google.maps.ZoomControlStyle.SMALL
},
mapTypeControl:true,
DragTableCursor:“移动”,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
$.ajax({
类型:“POST”,
url:'data.json',
数据类型:“json”,
成功:函数(数据){
位置。长度=0;
对于(p=0;p
如果要在地图上显示标记,需要创建标记并将其添加到地图中
$.ajax({
type: "POST",
url: 'http://supermobile.dk/html5/webApp.GMAP/json/demo.txt',
dataType: 'json',
success: function(data){
locations.length = 0;
for (p = 0; p < data.markers.length; p++) {
locations.push(Array(data.markers[p].latitude,data.markers[p].longitude));
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.markers[p].latitude,data.markers[p].longitude),
map: map,
title:"marker "+p
});
}
}
});
$.ajax({
类型:“POST”,
网址:'http://supermobile.dk/html5/webApp.GMAP/json/demo.txt',
数据类型:“json”,
成功:函数(数据){
位置。长度=0;
对于(p=0;p
$.ajax({
type: "POST",
url: 'http://supermobile.dk/html5/webApp.GMAP/json/demo.txt',
dataType: 'json',
success: function(data){
locations.length = 0;
for (p = 0; p < data.markers.length; p++) {
locations.push(Array(data.markers[p].latitude,data.markers[p].longitude));
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.markers[p].latitude,data.markers[p].longitude),
map: map,
title:"marker "+p
});
}
}
});