您的位置首页生活百科

Google 地图 API 自定义搜索控件

Google 地图 API 自定义搜索控件

function showAddress(){

var search = document.getElementById("address").value;

var point;

var marker;

var baseIcon = new GIcon(G_DEFAULT_ICON);

baseIcon.shadow = "

";

baseIcon.iconSize = new GSize(20, 34);

baseIcon.shadowSize = new GSize(37, 34);

baseIcon.iconAnchor = new GPoint(9, 34);

baseIcon.infoWindowAnchor = new GPoint(9, 2);

geocoder.getLocations(search, function (result){

delAllResult();

if (result.Status.code == G_GEO_SUCCESS) {

for (var i=0; i

var p = result.Placemark[i].Point.coordinates;

point = new GLatLng(p,p);

var letter = String.fromCharCode("A".charCodeAt(0) + i);

var letteredIcon = new GIcon(baseIcon);

letteredIcon.image = "

" + letter + ".png";

marker = new GMarker(point,{ icon:letteredIcon });

pointsArray[i]=point;

markersArray.push(marker);

map.addOverlay(marker);

myplace(marker,point,result.Placemark[i].address);

addNodeEvent(marker,point,result.Placemark[i].address,i);

}

adaptView(pointsArray);

}

else {

alert('不能找到: "'+search+ '",' + reasons[result.Status.code]);

}

});

}