缩小地图会给出错误的纬度长度机器人



如果我无法解释我的主题的情况,我很抱歉,但这就是问题所在。

每当我点击标记时,我在谷歌地图上有自定义标记(图像视图),它都会检索地址并显示在文本视图中。当我完全放大地图并点击标记时,它会给出完全正确的地址,但是当我缩小时,它仍然给出地址,但这次距离我的标记的确切点还有 1 或 2 个街区。太混乱了,有人能帮我解决哪里出了问题吗?

这是我的代码

    OnTouchListener imgSourceOnTouchListener
= new OnTouchListener(){
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        LatLng center = map.getCameraPosition().target;

        String filterAddress = "";
        Geocoder geoCoder = new Geocoder(
                getBaseContext(), Locale.getDefault());
        try {
            List<Address> addresses = geoCoder.getFromLocation(
                    center.latitude, 
                    center.longitude, 1);
            if (addresses.size() > 0) {
                for (int index = 0; 
                index < addresses.get(0).getMaxAddressLineIndex(); index++)
                    filterAddress += addresses.get(0).getAddressLine(index) + " ";
            }
        }catch (IOException ex) {        
            ex.printStackTrace();
        }catch (Exception e2) {
            // TODO: handle exception
            e2.printStackTrace();
        }
        touchedXY.setText(String.valueOf("address" +filterAddress));
        return true;

    }
};

首先,你不能以这种方式使用 Marker imgSource1 = (ImageView)findViewById(R.id.view); 应该在 Java 代码中添加标记,而不是像您所说的那样通过 id 从 xml 文件引用它。你必须设置setOnMapClickListener

 map.setOnMapClickListener(new OnMapClickListener() {
            public void onMapClick(LatLng arg0) {fromMarker = map.addMarker(new MarkerOptions()
                                .position(arg0));   }
        });

现在有一个标记将被放置在您触摸地图的位置,您可以使用此标记来显示地址,因此 zooking 或更改相机位置不会更改您按下的地址位置

相关内容

最新更新