Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle map custom marker based on database
    primarykey
    data
    text
    <p>In 2 weeks I explored much about Google maps. I am try read a forum and tutorial. But I got this problem when I am going to develop a GIS web. I am using Google maps apiv3, postgre database, and php. I have so much row in my database. Now I only can show multiple marker based on my database, but what I after is <strong>the marker have a unique icon based on column content in database</strong> like a type 1 = 1.png type 2 = 2.png. <strong>the problem is the type is too many</strong>, so it is impossible to definition them by manual (because so many type, I already have about 30 type of content in database column ) . I get database value using json. I've already try read forum and some tutorial, but I can't find the answer. sorry for my bad english. please help me, thanks. this is the code index.php and json.php :</p> <pre><code>&lt;html lang="en"&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; 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&lt;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); }); } &lt;/script&gt; </code></pre> <hr> <pre><code>&lt;?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; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload