2009-11-15 102 views
2

我有一個定製的谷歌地圖的不同點:如何更改Gmap標記顏色?

Markers[0] = new Array(new GMarker(new GLatLng(45.0, 9.0)), "Location1", "<strong>Address Line</strong><br/>Some information"); 
Markers[1] = new Array(new GMarker(new GLatLng(45.0, 12.0)), "Location2", "<strong>Address Line</strong><br/>Some information"); 

只要我想改變默認的紅色標記的顏色。 I.E.第二個藍色。

如何做到這一點?

回答

-1

這裏是一個簡單的代碼,允許谷歌地圖多種顏色標記

<?php 
$con = mysql_connect("localhost","root",""); 
$Db=mysql_select_db("map",$con); 
$select_det=mysql_query("select * from record"); 

// some code 
?> 
<html> 
<head> 
<title>EasyGoogleMap</title> 
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAPDUET0Qt7p2VcSk6JNU1sBSM5jMcmVqUpI7aqV44cW1cEECiThQYkcZUPRJn9vy_TWxWvuLoOfSFBw" type="text/javascript"></script> 
    </head> 
    <body onUnload="GUnload()"> 

<div id="map" style="width: 550px; height: 450px"></div> 
<script type="text/javascript"> 
var greenIcon = new GIcon(G_DEFAULT_ICON); 
greenIcon.image = "http://localhost/pointer_image/markerRd.png"; 
var markerOptions1 = {icon:greenIcon}; 

    var redIcon = new GIcon(G_DEFAULT_ICON); 
redIcon.image = "http://localhost/pointer_image/markerGr.png"; 
var markerOptions2 = {icon:redIcon}; 

var yIcon = new GIcon(G_DEFAULT_ICON); 
yIcon.image = "http://localhost/pointer_image/markerBl.png"; 
var markerOptions3 = {icon:yIcon}; 

    //<![CDATA[ 
    if (GBrowserIsCompatible()) { 


     // A function to create the marker and set up the event window 
     // Dont try to unroll this function. It has to be here for the function closure 
     // Each instance of the function preserves the contends of a different instance 
     // of the "marker" and "html" variables which will be needed later when the event triggers.  
     function createMarker(point,html,type) {  
     if(type=="b") 
     { 
     var marker = new GMarker(point, markerOptions1); 
     } 
     else if(type=="c") 
     { 
     var marker = new GMarker(point, markerOptions2); 
     } 
     else 
     { 
     var marker = new GMarker(point, markerOptions3); 
     } 
     GEvent.addListener(marker, "click", function() { 
      marker.openInfoWindowHtml(html); 
     });  
     return marker;  
     } 

     // Display the map, with some controls and set the initial location 
     var map = new GMap2(document.getElementById("map")); 
     map.addControl(new GLargeMapControl()); 
     map.addControl(new GMapTypeControl()); 
     <?php 
     while($fetch_record=mysql_fetch_array($select_det)) 
    { 
    ?> 
     map.setCenter(new GLatLng(<?php echo $fetch_record['lat'];?>,<?php echo $fetch_record['long'];?>),8); 

     // Set up three markers with info windows 

     var point = new GLatLng(<?php echo $fetch_record['lat'];?>,<?php echo $fetch_record['long'];?>); 
     var marker = createMarker(point,'<?php echo $fetch_record['desc'];?>','<?php echo $fetch_record['type'];?>') 
     map.addOverlay(marker); 

    <?php 
    } 
    ?> 

    } 

    // display a warning if the browser was not compatible 
    else { 
     alert("Sorry, the Google Maps API is not compatible with this browser"); 
    } 

    // This Javascript is based on code provided by the 
    // Community Church Javascript Team 
    // http://www.bisphamchurch.org.uk/ 
    // http://econym.org.uk/gmap/ 

    //]]> 
    </script> 
</body> 
</html> 

在這裏你必須從一個名爲「pointer_image」

文件夾把你的標記圖像

您可以通過調整代碼來更改標記圖像

通過編輯的代碼這一部分: -

<script type="text/javascript"> 
var greenIcon = new GIcon(G_DEFAULT_ICON); 
greenIcon.image = "http://localhost/pointer_image/markerRd.png"; 
var markerOptions1 = {icon:greenIcon}; 

    var redIcon = new GIcon(G_DEFAULT_ICON); 
redIcon.image = "http://localhost/pointer_image/markerGr.png"; 
var markerOptions2 = {icon:redIcon}; 

var yIcon = new GIcon(G_DEFAULT_ICON); 
yIcon.image = "http://localhost/pointer_image/markerBl.png"; 
var markerOptions3 = {icon:yIcon}; 

希望這會幫助你,我也提供數據庫THI它也是在波紋管------

-- phpMyAdmin SQL Dump 
-- version 2.11.4 
-- http://www.phpmyadmin.net 
-- 
-- Host: localhost 
-- Generation Time: Sep 19, 2011 at 12:48 PM 
-- Server version: 5.0.51 
-- PHP Version: 5.2.5 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 

-- 
-- Database: `map` 
-- 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `record` 
-- 

CREATE TABLE IF NOT EXISTS `record` (
    `id` int(11) NOT NULL auto_increment, 
    `lat` varchar(100) NOT NULL, 
    `long` varchar(100) NOT NULL, 
    `desc` varchar(200) NOT NULL, 
    `type` varchar(5) NOT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; 

-- 
-- Dumping data for table `record` 
-- 

INSERT INTO `record` (`id`, `lat`, `long`, `desc`, `type`) VALUES 
(1, '22.572646', '88.363895', 'kolkata', 'a'), 
(2, '22.982022', '88.440027', 'kalyani', 'b'), 
(3, '23.4', '88.5', 'krishnanagar', 'c'); 
+1

在關於JavaScript和Google地圖的問題中,MySQL語句似乎不相關。 – steampowered 2012-05-30 14:57:38