求解,google map 错误etMap: not an instance of Map
function search_map(){
var keyword=$("#keyword").val();
$.ajax({
url: "app_maps.php",
dataType:"json",
type:"POST",
data:{
"keyword":keyword,
"type":"search"
}
}).done(function(msg){
if(msg){
var name=msg.Name;
var address=msg.address;
var j=1;
//下面这一段是copy来的
var beaches = [
['Bondi Beach', 24.1424631, 120.6468703, 4],
['Coogee Beach',24.168649, 120.6490875, 5],
['Cronulla Beach', 24.1501231, 120.6490875, 3],
['Manly Beach', 24.1501231, 120.6391684, 2],
['Maroubra Beach', 24.1501231,120.6391684, 1]
];
for (var i = 0; i < beaches.length; i++) {
var beach = beaches[i];
var marker = new google.maps.Marker({
position: {lat: beach[1], lng: beach[2]},
map: map,
title: beach[0],
zIndex: beach[3]
});
}
}
});
}
我写了一个function 重点是把捞数据库里的东西。这一段一直标示不起来,后来我copy了一段程序 这段程序放在function 外是可以正常运作的,但放在function内,却是无法运作会显示:InvalidValueError: setMap: not an instance of Map; and not an instance of StreetViewPanorama
当然也爬了文 把map 换成 setMap ,这时没有错误讯息了,但还是没有标示。整段的程序是:
$(document).ready(function(){
var taipei = new google.maps.LatLng(25.08, 121.45);
var latlng=new google.maps.LatLng(24.1644833, 120.6575312);
var mapOptions = {
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
var map = new google.maps.Map(document.getElementById('mymap'),
mapOptions);
var marker = new google.maps.Marker({
title: "现在位置", //显示文字
icon:'images/big.png',
map: map //指定要放置的地图对象
});
if(window.navigator.geolocation){
var geolocation=window.navigator.geolocation;
geolocation.getCurrentPosition(getPositionSuccess);
}else{
alert("你的浏览器不支持地理定位");
map.setCenter(taipei);
}
function getPositionSuccess(position){
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
//定位到目前位置
map.setCenter(initialLocation);
marker.setPosition(initialLocation);
}
});
function search_map(){
var keyword=$("#keyword").val();
$.ajax({
url: "app_maps.php",
dataType:"json",
type:"POST",
data:{
"keyword":keyword,
"type":"search"
}
}).done(function(msg){
if(msg){
var name=msg.Name;
var address=msg.address;
var j=1;
var beaches = [
['Bondi Beach', 24.1424631, 120.6468703, 4],
['Coogee Beach',24.168649, 120.6490875, 5],
['Cronulla Beach', 24.1501231, 120.6490875, 3],
['Manly Beach', 24.1501231, 120.6391684, 2],
['Maroubra Beach', 24.1501231,120.6391684, 1]
];
for (var i = 0; i < beaches.length; i++) {
var beach = beaches[i];
var marker = new google.maps.Marker({
position: {lat: beach[1], lng: beach[2]},
map: map,
title: beach[0],
zIndex: beach[3]
});
}
}
});
}
地中海之魂
9 years, 2 months ago