2016-10-03 121 views
2

我正在使用谷歌地圖版本3.我想顯示一個方形標記。目前谷歌顯示它像下面的圖像。即該點在標記的底部取得。我的標記是假設20px X 20px。目前谷歌顯示在紅點。谷歌地圖標記偏移

enter image description here

現在我需要顯示標記小幅回落。即點應該不是在底部而是在中間。如下圖所示。

enter image description here

我都試過了,錨,anchorPosition,anchorPoint,仍然沒有運氣。

任何人都可以指出我做到這一點的確切方法嗎?

編輯 下面是我的代碼,

icon = { 
       url: "/app/image/map_pin/marker-90.png", 
       size: new google.maps.Size(32, 33), 
       origin: new google.maps.Point(0, 0), 
       anchor: new google.maps.Point(50,50) 

      } 


this.makeMarker(this.map,LatLong, icon); 


makeMarker(map: any, lat: number, lng: number, icon: string) { 
     new google.maps.Marker({ 
      map: map, 
      icon: icon, 
      animation: google.maps.Animation.DROP, 
      position: { lat: lat, lng: lng } 
     }); 
    } 

我試着用lat: 23.038645, lng: 72.511895這是在艾哈邁達巴德,Gujara,印度。但縮小後顯示在阿富汗的點。

+1

它的尺寸,產地,錨的組合。你見過這個嗎? https://developers.google.com/maps/documentation/javascript/examples/icon-complex –

+0

我已經使用過,請參閱我編輯的問題 – Akshay

+0

您可以在您的問題中發佈圖標(或圖標本身)的有效網址? – geocodezip

回答

2

the documentation,這個工程:

var icon = { 
    url: "http://i.stack.imgur.com/FhryS.png", // 20px x 20px icon 
    // size: new google.maps.Size(20, 20), // size of icon is 20px x 20px (so this isn't required) 
    // origin: new google.maps.Point(0, 0), // this is the default and isn't needed 
    anchor: new google.maps.Point(10, 10) // anchor is in the center at 10px x 10px 
} 

function initialize() { 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     center: new google.maps.LatLng(37.4419, -122.1419), 
 
     zoom: 13, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 
    var icon = { 
 
    url: "http://i.stack.imgur.com/FhryS.png", 
 
    anchor: new google.maps.Point(10, 10) 
 
    }; 
 
    makeMarker(map, map.getCenter().lat(), map.getCenter().lng(), icon); 
 
} 
 
google.maps.event.addDomListener(window, "load", initialize); 
 

 
function makeMarker(map, lat, lng, icon) { 
 
    new google.maps.Marker({ 
 
    map: map, 
 
    icon: icon, 
 
    animation: google.maps.Animation.DROP, 
 
    position: { 
 
     lat: lat, 
 
     lng: lng 
 
    } 
 
    }); 
 
}
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map_canvas"></div>

enter image description here