1
在2周内我对Google地图进行了大量探索。我尝试阅读论坛和教程。但是当我开发一个GIS网络时,我遇到了这个问题。我正在使用Google地图apiv3,postgre数据库和php。我的数据库里有很多行。现在我只能根据我的数据库显示多个标记,但是我之后是标记具有基于数据库中的列内容的独特图标,如类型1 = 1.png type 2 = 2.png。 问题是类型太多,所以不可能通过手工来定义它们(因为这么多类型,我在数据库列中已经有大约30种类型的内容)。我使用json获取数据库值。我已经尝试阅读论坛和一些教程,但我找不到答案。对不起,我的英语不好。请帮助我,谢谢。 这是代码的index.php和json.php:基于数据库的Google地图自定义标记
<html lang="en">
<head>
<script type="text/javascript">
function initialize(){
var peta;
var gambar_tanda;
gambar_tanda = 'assets/images/enseval.jpg';
var x = new Array();
var y = new Array();
var customer_name = new Array();
var rayon_name = new Array();
// posisi default peta saat diload
var lokasibaru = new google.maps.LatLng(-1.2653859,116.83119999999997);
var petaoption = {
zoom: 5,
center: lokasibaru,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
peta = new google.maps.Map(document.getElementById("map_canvas"),petaoption);
var infowindow = new google.maps.InfoWindow({
content: ''
});
// memanggil function ambilpeta() untuk menampilkan koordinat
url = "json.php";
$.ajax({
url: url,
dataType: 'json',
cache: false,
success: function(msg){
for(i=0;i<msg.enseval.customer.length;i++){
x[i] = msg.enseval.customer[i].x;
y[i] = msg.enseval.customer[i].y;
customer_name[i] = msg.enseval.customer[i].nama_customer;
//rayon_name[i] = msg.enseval.customer[i].nama_rayon
var point = new google.maps.LatLng(parseFloat(msg.enseval.customer[i].x),parseFloat(msg.enseval.customer[i].y));
tanda = new google.maps.Marker({
position: point,
map: peta,
icon: gambar_tanda,
clickable: true
});
bindInfoWindow(tanda, peta, infowindow, msg.enseval.customer[i].nama_customer );
}
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
function bindInfoWindow(tanda, peta, infowindow, data) {
google.maps.event.addListener(tanda, 'click', function() {
infowindow.setContent(data);
infowindow.open(peta, tanda);
});
}
</script>
<?php
require ('config.php');
$rayon = $_POST['rayon'];
$cabang = $_POST['org_id'];
//echo "$rayon, $cabang, $rayonhasil";
$sql = "SELECT distinct org_id, customer_name, attribute16, attribute17 FROM hasilgis";
$data = pg_query($sql);
$json = '{"enseval": {';
$json .= '"customer":[ ';
while($x = pg_fetch_array($data)){
$json .= '{';
$json .= '"id_customer":"'.$x['org_id'].'",
"nama_customer":"'.htmlspecialchars($x['customer_name']).'",
"x":"'.$x['attribute17'].'",
"y":"'.$x['attribute16'].'"
},';
}
$json = substr($json,0,strlen($json)-1);
$json .= ']';
$json .= '}}';
echo $json;
?>
非常感谢。但有很多种类型,因为在我的数据上,一个对象有10-30个类型,我有43个对象加上有一个唯一的类型,所以可能是我有30 * 43型。但是这个例子很简单,我只需要为每个正在运行的程序显示一个对象。所以我还可以重命名为1.jpg吗?对不起,我的英语不好。 – Krichevskoy
嗯,我不确定你的意思 - 你可以任意命名你的图标。您只需定义您想要为每个对象显示哪种类型 - 它不必与从数据库中获取的类型相对应。 – gawi
我解决了这个问题,我错过了主要想法,非常感谢gawi .. :) – Krichevskoy