2012-07-01 225 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