Android / Google 地图无法缩放至地理编码位置

发布于 2024-12-21 11:00:37 字数 1505 浏览 3 评论 0原文

我正在浏览一些教程,并且需要反转地理编码地址,但我无法使示例正常工作。地图已显示,但未缩放到我的地理编码位置。这是我的代码...

public class MapsActivity extends MapActivity {
    MapView mapView;
    MapController mc;
    GeoPoint p;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapshow);
        mapView = (MapView) findViewById(R.id.mapView);
        mc = mapView.getController();
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
        View zoomView = mapView.getZoomControls();

        zoomLayout.addView(zoomView,
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        mapView.displayZoomControls(true);
        Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
        try {
            List<Address> addresses = geoCoder.getFromLocationName(
                "empire state building", 15);
            String add = "";
            if (addresses.size() > 0) {
                p = new GeoPoint(
                    (int) (addresses.get(0).getLatitude() * 1E6),
                    (int) (addresses.get(0).getLongitude() * 1E6));
                mc.animateTo(p);
                mapView.invalidate();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

I am scrounging through some tutorials and am needing to reverse geocode addresses, but I can't get the examples working. The map displays, but it does not zoom to my geocoded location. Here is my code...

public class MapsActivity extends MapActivity {
    MapView mapView;
    MapController mc;
    GeoPoint p;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapshow);
        mapView = (MapView) findViewById(R.id.mapView);
        mc = mapView.getController();
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
        View zoomView = mapView.getZoomControls();

        zoomLayout.addView(zoomView,
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        mapView.displayZoomControls(true);
        Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
        try {
            List<Address> addresses = geoCoder.getFromLocationName(
                "empire state building", 15);
            String add = "";
            if (addresses.size() > 0) {
                p = new GeoPoint(
                    (int) (addresses.get(0).getLatitude() * 1E6),
                    (int) (addresses.get(0).getLongitude() * 1E6));
                mc.animateTo(p);
                mapView.invalidate();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-12-28 11:00:37

首先检查

它是否给您任何错误日志?..您是否尝试过其他地址?,尝试写城市名称...您是否在模拟器中尝试此操作..然后在设备中测试,因为地理编码器类在模拟器中不起作用..如果 api 级别是 2.2..尝试将其更改为更低和更高..可能是因为缩放级别你无法识别结果..将其设置为 mc.setZoom(16);

然后检查

我怀疑问题出在内部以查看结果。写一些美国境外的地址,看看是否有任何差异。

最后,

如果您有设备..尝试您的代码..我确信它会正常运行或使用更高版本的模拟器。

First Check

Does it give you any error log?..Have you tried with another addresses?,Try writting city name ...Are you trying this in emulator..then test in device cause Geocoder class don't work in emulator..if api level is 2.2..try changing it to lower and higher..may be because of zoom level you can't recognize the result..set it to mc.setZoom(16);

Then Check

I suspect the problem is within to see the result..write some Address outside the US and see if there is any difference.

Finally

If you have Device..try your code on it..and I am sure It will run ok or Use higher version Emulator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文