按纬度和经度放置标记

时间:2012-07-01 16:25:00

标签: google-maps-api-3 location gwt2

我有这个代码,假设通过latlng

放置标记
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 个答案:

答案 0 :(得分:1)

当使用Geocoder进行反向地理编码(将LatLng转换为地址)时,您将始终获得最近的地址(如果可以确定)。如果要使用原始坐标,只需使用原始坐标放置Marker。如果您要将LatLng转换为Google Geocoder可以转到某个地址的最接近的地址,结果将始终为您提供最接近的已知street_address,{{1}的LatLng },routeairporttransit_stationneighborhoodsublocality等。

相关问题