2012-07-01 228 views
2

我有這樣的代碼,假設由經緯度將經度和緯度

public void initialize() { 
    geocoder = Geocoder.create(); 
    myOptions = MapOptions.create();   
    myOptions.setZoom(18); 
    myOptions.setMapTypeId(MapTypeId.HYBRID); 
    myOptions.setMapMaker(true); 
    map = GoogleMap.create(
     Document.get().getElementById("map_canvas"),myOptions);  

    GeocoderRequest request = GeocoderRequest.create();     
    request.setLocation(LatLng.create(lat,lng)); 

    geocoder.geocode(request, new Callback() { 
     public void handle(JsArray<GeocoderResult> rslts, GeocoderStatus status) 
     { 
      if (status == GeocoderStatus.OK) { 
       location = rslts.get(0); 
       map.setCenter(location.getGeometry().getLocation()); 
       marker = Marker.create(); 
       marker.setMap(map); 
       marker.setPosition(location.getGeometry().getLocation()); 
      } 
     } 
    }); 

當我與這些座標(45.48592686713835-73.49009937672122)測試,以放置標記標記 我只得到這是最近地址圖標A.但我真正想要的是用綠色箭頭顯示的確切位置。

enter image description here

我這麼想嗎?

回答

1

使用Geocoder做反向地理編碼(將LatLng轉換爲地址)時,您將始終獲得最接近的地址(如果可以確定的話)。如果要使用原始座標,只需使用原始座標將Marker。如果你打算到經緯度轉換爲地址或最接近的是,谷歌Geocoder可以得到一個地址,結果將永遠給你已知street_address最近的經緯度,routeairporttransit_stationneighborhoodsublocalitylocality,等

+0

我做了你的建議,但現在我有這個奇怪的異常http://stackoverflow.com/questions/11284367/weird-exception-when-placing-a-marker-with-latlng – outellou