更改街景< - >卫星谷歌地图的Andr​​oid [英] Changing StreetView<->Satellite Google Maps Android

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

问题描述

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

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

下面是我的code:

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?

谢谢, preXX

推荐答案

当你说这是行不通的,我们真的需要更多的信息,试图帮助你!它会崩溃,不是停留在街道/星期六查看或只是法线贴图等,尽量给更多的信息,如果它坠毁后的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:

(编辑:我只是想它不调用无效和它的作品所以它必须是菜单按钮的ID)

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

mapView.invalidate();

您需要调用此为了使图形页面刷新自己,所以每次调用它,你改变图形页面设置。

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

如果那不工作,那么它可能是你的ID的按钮中的arent你的交换机识别所以尽量设置你的菜单为XML文件INT RES /菜单/像:

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>

然后修改code到:

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;卫星谷歌地图的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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