dongyin8991 2015-09-08 14:08
浏览 168

如何在谷歌地图上选择多个标记

I am New to google maps and php, Assume that I have 100 markers on map and I want to select some 15 markers from them if the markers clicked it changes the color of the marker and do some action..In this code If i click the marker it just show the popup which get the data's from database.

Here is my google map initialize code using php ..any help friends

 <html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
 <title>Google Map API V3 with markers</title>
 <style type="text/css">
 body { font: normal 10pt Helvetica, Arial; }
 #map { width: 800px; height: 600px; border: 0px; padding: 0px; }
 </style>
 <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript>
 <script type="text/javascript">
   var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
   new google.maps.Size(32, 32), new google.maps.Point(0, 0),
   new google.maps.Point(16, 32));
   var center = null;
   var map = null;
   var currentPopup;
   var bounds = new google.maps.LatLngBounds();
   function addMarker(lat, lng, info) {
   var pt = new google.maps.LatLng(lat, lng);
   bounds.extend(pt);
   var marker = new google.maps.Marker({
   position: pt,
   icon: icon,
   map: map
   });
   var popup = new google.maps.InfoWindow({
   content: info,
   maxWidth: 300
   });
   google.maps.event.addListener(marker, "click", function() {
    if (currentPopup != null) {
     currentPopup.close();
     currentPopup = null;
     }
    popup.open(map, marker);
    currentPopup = popup;
    });
   google.maps.event.addListener(popup, "closeclick", function() {
   map.panTo(center);
   currentPopup = null;
   });
   }
   function initMap() {
   map = new google.maps.Map(document.getElementById("map"), {
   center: new google.maps.LatLng(0, 0),
   zoom: 5,
   mapTypeId: google.maps.MapTypeId.ROADMAP,
   mapTypeControl: false,
   mapTypeControlOptions: {
   style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
    },
   navigationControl: true,
   navigationControlOptions: {
   style: google.maps.NavigationControlStyle.SMALL
   }
   });

   <?php
   $query = pg_query("SELECT * FROM example");
   while ($row = pg_fetch_array($query)){
   $name=$row['name'];
   $lat=$row['lat'];
   $lon=$row['lon'];
   $desc=$row['description'];
   echo ("addMarker($lat, $lon,<b>$name</b><br/>$desc');
");
   }
   ?>

   center = bounds.getCenter();
   map.fitBounds(bounds);
    }
   </script>
   </head>
   <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
   <div id="map"></div>
   </html>
  • 写回答

1条回答 默认 最新

  • dongshi6528 2015-09-09 13:15
    关注

    Try this (in your code, somewhere around line 40):

    google.maps.event.addListener(marker, "click", function() {
      this.setIcon({url: 'http://maps.google.com/mapfiles/ms/micons/purple.png'});
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?