程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP基礎知識 >> php+js MAPABC 地圖調用的簡單例子

php+js MAPABC 地圖調用的簡單例子

編輯:PHP基礎知識
 

<?php
//經度_緯度_標題_地址_電話_類型_標題的鏈接地址
$data = array(
"116.304137_39.983821_title1_addurl1_tel1_type1_http://www.baidu.com",
"116.316345_39.977596_title2_addurl2_tel2_type2_http://www.sina.com",
"116.343048_40.000118_title3_addurl3_tel3_type3_http://www.163.com",
//"116.3096839_39.9843957_title4_addurl4_tel4_type4"
);
$data_str = implode('||',$data); //組合為sting
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>關鍵字搜索</title>

<script type="text/javascript" src="http://app.mapabc.com/apis?&t=

flashmap&v=2.4&key=b0a7db0b3a30f944a21c3682064dc70ef5b738b062f64

79a5eca39725798b1ee300bd8d5de3a4ae3|29e8ed1f7f6a97d8e99

fc568cea6a7dc0ccd920856e07c0718b9885faf7551a18141699c81f526d7"></script>

<script type="text/javascript">
var mapObj=null;
function mapInit(data) {
var mapoption = new MMapOptions();
mapoption.toolbar = MConstants.ROUND; //設置地圖初始化工具條,ROUND:新版圓工具條
mapoption.toolbarPos=new MPoint(20,20); //設置工具條在地圖上的顯示位置
mapoption.overviewMap = MConstants.SHOW; //設置鷹眼地圖的狀態,SHOW:顯示,HIDE:隱藏(默認)
mapoption.scale = MConstants.SHOW; //設置地圖初始化比例尺狀態,SHOW:顯示(默認),HIDE:隱藏。
mapoption.zoom = 13;//要加載的地圖的縮放級別
mapoption.center = new MLngLat(116.397428,39.90923);//要加載的地圖的中心點經緯度坐標
mapoption.language = MConstants.MAP_CN;//設置地圖類型,MAP_CN:中文地圖(默認),MAP_EN:英文地圖
mapoption.fullScreenButton = MConstants.SHOW;//設置是否顯示全屏按鈕,SHOW:顯示(默認),HIDE:隱藏
mapoption.centerCross = MConstants.SHOW;//設置是否在地圖上顯示中心十字,SHOW:顯示(默認),HIDE:隱藏
mapoption.requestNum=100;//設置地圖切片請求並發數。默認100。
mapObj = new MMap("map", mapoption); //地圖初始化

//自動加載點-start
var resultCount=10;
keywordSearch_CallBack(data);
//-end

}
/*
function keywordSearch(){
var keywords = document.getElementById("keyword").value;
var city = document.getElementById("city").value;
var MSearch = new MPoiSearch();
var opt = new MPoiSearchOptions();
opt.recordsPerPage = 10;//每頁返回數據量,默認為10
opt.pageNum = 1;//當前頁數。
opt.dataType = "";//數據類別,該處為分詞查詢,只需要相關行業關鍵字即可
opt.dataSources = MConstants.DS_BASE_ENPOI;//數據源,基礎+企業地標數據庫(默認)
MSearch.setCallbackFunction(keywordSearch_CallBack);
MSearch.poiSearchByKeywords(keywords,city,opt);
}
var resultCount=10;
*/
function keywordSearch_CallBack(data){
var resultStr="";
/*
var data = new Array(
"116.304137_39.983821_title1_addurl1_tel1_type1",
"116.316345_39.977596_title2_addurl2_tel2_type2",
"116.343048_40.000118_title3_addurl3_tel3_type3",
"116.3096839_39.9843957_title4_addurl4_tel4_type4"
);
*/
data = data.split('||'); //拆分傳參值成為數組
if(data.length<0){
resultStr="未查找到任何結果!<br/>建議:<br/>1.請確保所有字詞拼寫正確。<br/>2.嘗試不同的關鍵字。<br/>3.嘗試更寬泛的關鍵字。";
}else{
var marker = new Array();
resultCount=data.length;
for (var i = 0; i < data.length; i++) {
data_str = data[i];
data_arr = data_str.split('_');
resultStr += "<div id='divid"+(i)+"' onmouseover='openMarkerTipById1("+(i)+",this)'

onmouseout='onmouseout_MarkerStyle("+(i+1)+",this)' style=\"font-size: 13px;

cursor:pointer;padding:2px 0 10px 5px;\">"+(i+1)+"、"+data_arr[2]+"<br \/>";

resultStr += TipContents(data_arr[5],data_arr[3],data_arr[4]);
resultStr += "<br \/></div>";
//resultStr += "<br />城市:"+data.poilist[i].citycode + "<br \/></div>";

var markerOption = new MMarkerOptions();
markerOption.imageUrl ="http://code.mapabc.com/images/lan_1.png";
markerOption.picAgent = false;

var tipOption = new MTipOptions();
tipOption.title="<a href='"+data_arr[6]+"'>"+(i+1) + ". "+ data_arr[2]+"<\/a>";
var tipC = "<br />"+TipContents(data_arr[5],data_arr[3],data_arr[4]);
tipOption.content=tipC;//tip內容
tipOption.hasShadow=true;
tipOption.titleFontStyle.name="Arial";
tipOption.titleFontStyle.size=12;
tipOption.titleFontStyle.color= 0x005cb5;
tipOption.titleFontStyle.bold=true;
tipOption.contentFontStyle.name="Arial";
tipOption.contentFontStyle.size=13;
tipOption.contentFontStyle.color= 0x000000 ;
tipOption.contentFontStyle.bold=false;

markerOption.tipOption = tipOption;
markerOption.canShowTip=true;
markerOption.hasShadow=true;
var mar = new MMarker(new MLngLat(data_arr[0],data_arr[1]),markerOption);
mar.id=(i);
marker.push(mar);
}
mapObj.addOverlays(marker,true);
mapObj.addEventListener(mapObj,MConstants.TIP_OPEN,openTip);
}
document.getElementById("result").innerHTML = resultStr;
}


function TipContents(type,address,tel){
if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {
type = "暫無";
}
if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {
address = "暫無";
}
if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {
tel = "暫無";
}
var str ="地址:" + address + "<br>電話:" + tel + " <br>類型:"+type;
return str;
}
function openMarkerTipById1(pointid,thiss){ //根據id打開搜索結果點tip
thiss.style.background='#CFD6E8';
mapObj.openOverlayTip(pointid);
}
function onmouseout_MarkerStyle(pointid,thiss) {//鼠標移開後點樣式恢復
thiss.style.background="";
}
function openTip(param){
var n = "divid"+(param.overlayId);
for (var i = 0; i < resultCount; ++i){
var id="divid"+i;
document.getElementById(id).style.background='';
document.getElementById(id).onmouseout = function(){this.style.backgroundColor='';};
}
document.getElementById(n).style.background='#CFD6E8';
document.getElementById(n).onmouseout = function(){this.style.backgroundColor='#CFD6E8';};
}
</script>
</head>
<body onload='mapInit("<?php echo $data_str?>");'>
<table width="989" border="0" cellpadding="0" cellspacing="0" bgcolor="#DDDDDD">

<tr height="100%">
<td rowspan="2"><div id="map" style="height:600px; width:750px"></div></td>
<!--
<td style="width:247px;border-left:1px solid #666;">
<div style="padding:5px 0px 0px 5px;font-size:12px;height:94px;">關鍵字搜索
<br />城 市:<input type="text" id="city" name="city" value="010" />
<br />關鍵字:<input type="text" id="keyword" name="keyword" value="中關村"/><br /><input type="button" value="查詢" onclick="keywordSearch()" style="margin-left:100px"/>
</div>
</td>
-->
</tr>

<tr>
<td style="width:247px;border-left:1px solid #666;border-top:1px solid #666;">
<div id="result" name="result" style="height:600px;overflow:auto;width:247px;"></div>
</td>
</tr>
</table>
</body>
</html>
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved