一,后台添加标记
/*#latlng是经纬度的文本框*/
/*#title是地址的文本框*/
/*获取地址需要你的应用开启webservice*/
qq.maps.event.addListener(map, "click", function (e) {
$('#latlng').val(e.latLng.getLng().toFixed(6) + "," + e.latLng.getLat().toFixed(6));
url3 = encodeURI("https://apis.map.qq.com/ws/geocoder/v1/?location=" + e.latLng.getLat() + "," + e.latLng.getLng() + "&key=ukey&output=jsonp&&callback=?");
$.get(url3, function (result) {
if(result.result!=undefined){
$('#title').val(result.result.address);
}
})
});
二,前台显示标记
/*data_info是服务器获取的标记数据集*/
/*item.content是后台添加的自定义内容*/
data_info = jQuery.parseJSON($(".val").val());
for(var i=0;i<data_info.length;i++){
var item = data_info[i];
var mkr = new qq.maps.LatLng(item.lat,item.lng);
var marker = new qq.maps.Marker({
position: mkr,
map: map
});
var title = item.title;
var content = item.content;
addClickHandler(title,content,marker);
}
function addClickHandler(title,content,marker){
qq.maps.event.addListener(marker, 'click', function(){
info.open();
info.setContent('<div class="popinf"><h4>'+title+'</h4>'+content+'</div>');
info.setPosition(marker);
});
}