Android的谷歌地图卫星切换 [英] Android-Google Maps Satellite toggle

查看:326
本文介绍了Android的谷歌地图卫星切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加按钮,将在地图视图普通和卫星视图之间切换和我不断收到一个应用程序已意外停止错误

 公共类NewMapsActivity扩展MapActivity
{
    私人MapView类myMapView;    @覆盖
        保护无效的onCreate(捆绑冰柱)
    {
        super.onCreate(冰柱);
        的setContentView(R.layout.main);        MapView的myMapView =(图形页面)findViewById(R.id.mapview);        按钮mySatelliteButton =(按钮)findViewById(R.id.c_button);
        mySatelliteButton.setOnClickListener(新View.OnClickListener()
        {
           公共无效的onClick(视图v)
            {
                SetSatellite();
            }
        });
     myMapView.setBuiltInZoomControls(真);
     }    私人无效SetSatellite()
        {
            如果(myMapView.isSatellite())
                myMapView.setSatellite(假);
            其他
                myMapView.setSatellite(真);
        }    @覆盖
        保护布尔isRouteDisplayed()
     {
            返回false;
     }
}


解决方案

如果一切赋予的权利,然后检查空指针异常是否发生在myMapview对象。既然你已经宣布在顶部,然后里面的onCreate您使用的是图形页面mymapView =(图形页面)findViewById(R.id.mapview);所以,当你使用内部setStallite mymapview对象()这将只需要这是在顶部声明的对象。那么试试这个

  myMapView =(图形页面)findViewById(R.id.mapview);

但你在顶部,图形页面myMapview声明myMapview;

检查这个如果不是请在发布您的logcat中误差

I want to add button which will toggle between normal and satellite view in the map view and I keep getting a the application has stopped unexpectedly error

public class NewMapsActivity extends MapActivity 
{    
    private MapView myMapView;

    @Override
        protected void onCreate(Bundle icicle) 
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        MapView myMapView = (MapView) findViewById(R.id.mapview);

        Button mySatelliteButton = (Button)findViewById(R.id.c_button);
        mySatelliteButton.setOnClickListener(new View.OnClickListener()
        {
           public void onClick(View v)
            {
                SetSatellite();
            }
        });
     myMapView.setBuiltInZoomControls(true);
     }

    private void SetSatellite()
        {
            if ( myMapView.isSatellite() )
                myMapView.setSatellite(false);
            else 
                myMapView.setSatellite(true);
        }

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

解决方案

If everything is given right then check whether nullpointer exception occur in myMapview object. since you have declared at top then inside onCreate you are using MapView mymapView=(MapView) findViewById(R.id.mapview); so when you use mymapview object inside setStallite() it will take only the object which was declare at the top. so try this

  myMapView = (MapView) findViewById(R.id.mapview);

but you to declare myMapview at top as MapView myMapview;

check this if not please post your error in logcat

这篇关于Android的谷歌地图卫星切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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