更改街景<->卫星 Google 地图 Android [英] Changing StreetView<->Satellite Google Maps Android

查看:24
本文介绍了更改街景<->卫星 Google 地图 Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过菜单按钮在街景和卫星之间切换我的 GoogleMaps 视图.

i wanna switch my GoogleMaps view between StreetView and Satellite via menubutton.

这是我的代码:

public boolean onCreateOptionsMenu(Menu menu){

    menu.add(0, 0, 0, "StreetView");
    menu.add(0, 0, 1, "Satellite");

    return true;
}

public boolean onOptionsItemSelected (MenuItem item){

    switch (item.getItemId()){
        case 0:
            mapView.setStreetView(true);
        return true;

        case 1 :
            mapView.setSatellite(true);
        return true;

    }

    return false;
}

不起作用..我怎么了?

Won't work.. what do i wrong?

谢谢,前缀

推荐答案

当您说它不起作用时,我们确实需要更多信息来尝试帮助您!它是否崩溃,它是否停留在街景/卫星视图或只是普通地图等,尝试提供更多信息,如果它崩溃,请发布 logcat 的副本.

When you say it doesn't work, we really need more info to try and help you! Does it crash, does it stay on Street/Sat View or just normal map etc, try to give more info and if it crashed post a copy of the logcat.

我认为您缺少的只是一行:

I think all you are missing is the line:

(我只是在没有调用 invalidate 的情况下尝试了它并且它可以工作,所以它必须是菜单按钮 ID)

( I just tried it without calling invalidate and it works so it must be the menu button ID's)

mapView.invalidate();

您需要调用它以使 mapView 自行刷新,因此每次更改 mapView 设置时都调用它.

You need to call this in order for the mapView to refresh itself, so call it every time you change the mapView settings.

如果这不起作用,那么可能是您的开关无法识别按钮的 ID,因此请尝试将菜单设置为 xml 文件 int res/menu/之类:

If that doesnt work then it may be your id's for the buttons arent recognised in your switch so try setting up your menu as an xml file int res/menu/ like:

<?xml version="1.0" encoding="utf-8"?>
<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:title="Street View" android:numericShortcut="1" android:id="@+id/mapStreet" ></item>
  <item android:title="Sat View" android:numericShortcut="2" android:id="@+id/mapSat"></item>
</menu>

然后将您的代码修改为:

Then modify your code to:

public boolean onCreateOptionsMenu(Menu menu){
    super.onCreateOptionsMenu(menu);
    MenuInflater oMenu = getMenuInflater();
    oMenu.inflate(R.menu.mapsmenu, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()){
    case R.id.mapStreet:
         mapView.setStreetView(true);
         mapView.setSatellite(false);
         mapView.invalidate();
         return true;

    case R.id.mapSat:
         mapView.setSatellite(true);
         mapView.setStreetView(false);
         mapView.invalidate();
         return true;
    }
    return false;
}

这篇关于更改街景&lt;-&gt;卫星 Google 地图 Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆