MyLocationOverlay问题 [英] MyLocationOverlay problem

查看:115
本文介绍了MyLocationOverlay问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私人无效initMyLocation(){
        myLocOverlay =新MyLocationOverlay(这一点,MYMAP);
        myLocOverlay.enableCompass();
        myLocOverlay.enableMyLocation();
        。myMap.getOverlays()加(myLocOverlay);
        如果(myLocOverlay == NULL)
    {
        assignFirstLoc();

    }


如果(myLocOverlay!= NULL)
            {
                Log.e(错误,1);
                p值=新的GeoPoint((int)的(myLocOverlay.getMyLocation()getLatitudeE6()),(int)的(myLocOverlay.getMyLocation()getLongitudeE6())。。);
                MC = myMap.getController();
                mc.animateTo(对);
                mc.setCenter(对);

            }
 

我看到在logcat中错误1的消息,但在那之后我花了一个空指针异常我不知道为什么,我相信我检查myLocOverlay为空或不是用如果块..任何suggesstions?

编辑:

这是所分配的firtst值我assignedGFirstLoc方式:

 私人无效assignFirstLoc()
    {
        最后弦乐坐标[] = {41.00527,28.97696};
        双LAT2 = Double.parseDouble(坐标[0]);
        双lng2 = Double.parseDouble(坐标[1]);
        P =新的GeoPoint((INT)(LAT2 * 1E6),(INT)(lng2 * 1E6));
        myMap.getController()setZoom(16)。
        。myMap.getController()animateTo(对);
        myMap.getController()setCenter(p)的。

    }
 

解决方案

MyLocationOverlay 只能用于显示的位置,距离感应器来了。 你不能设置。 你有一个空指针,因为 MyLocationOverlay.getMyLocation()返回null。传感器没有赶上地理位置尚未时间。

如果你想显示的位置时,传感器得到了你可以做到这一点的数据:

  mMyLocationOverlay.runOnFirstFix(新的Runnable(){公共无效的run(){
        。mapView.getController()animateTo(mMyLocationOverlay.getMyLocation());
}});
 

如果你想显示在任意波形的位置(经纬度值)的项目,你需要实现自己的版本 ItemizedOverlay 的 你可以找到SDK文档中的为例:谷歌地图查看教程,第2部分AddingOverlayItem

如果你只是想显示在地图上的任意位置,你不需要覆盖。只是调用你的函数,它会工作:

 私人无效initMyLocation(){
    assignFirstLoc();
}
 

private void initMyLocation() {
        myLocOverlay = new MyLocationOverlay(this, myMap);
        myLocOverlay.enableCompass();
        myLocOverlay.enableMyLocation();
        myMap.getOverlays().add(myLocOverlay);
        if (myLocOverlay == null)
    { 
        assignFirstLoc();

    }


if (myLocOverlay != null)
            {
                Log.e("error","1");
                p = new GeoPoint((int) (myLocOverlay.getMyLocation().getLatitudeE6()), (int) (myLocOverlay.getMyLocation().getLongitudeE6()));
                mc = myMap.getController();
                mc.animateTo(p);
                mc.setCenter(p); 

            } 

I saw "error 1" message in the logcat but after that I took an null pointer exception I dont know why, I believe I check myLocOverlay is null or not with "if" block.. Any suggesstions?

Edit:

This is my assignedGFirstLoc method that assigned the firtst values:

private void assignFirstLoc()
    {
        final String coordinates[] = {"41.00527", "28.97696"};
        double lat2 = Double.parseDouble(coordinates[0]);
        double lng2 = Double.parseDouble(coordinates[1]);
        p = new GeoPoint((int) (lat2 * 1E6), (int) (lng2 * 1E6));
        myMap.getController().setZoom(16);
        myMap.getController().animateTo(p);
        myMap.getController().setCenter(p);

    }

解决方案

MyLocationOverlay can only be used to show a location coming from sensors. You cannot set it. You got a NullPointer because MyLocationOverlay.getMyLocation() returns null. Sensors didn't have the time to catch the geolocation yet.

If you want to show the location when the sensor got the data you can do this:

mMyLocationOverlay.runOnFirstFix(new Runnable() { public void run() {
        mapView.getController().animateTo(mMyLocationOverlay.getMyLocation());
}});

If you want to display an item in an arbitray location (with latitude and longitude values) you need to implement your own version of ItemizedOverlay You can find an exemple in the SDK documentation: Google Map View tutorial, Part2 AddingOverlayItem

If you just want to show an arbitrary location on the map, you don't need an overlay. just call your function and it will work:

private void initMyLocation() {
    assignFirstLoc();
}

这篇关于MyLocationOverlay问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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