如何正确使用drawMyLocation [英] How to properly use drawMyLocation

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

问题描述

我想显示用户的当前位置与默认的蓝色圆点机器人。在我的地图页面上我也有一个布局,显示不同的兴趣点。有林麻烦找出放什么的一些变量,并想知道,如果有人可以帮助我。

I am trying to show the users current location with the default blue dot in android. In my maps page I also have a layout that shows different points of interest. Im having trouble figuring out what to put for some of the variables and was wondering if someone could help me out.

这是我使用的是什么,到目前为止,以显示我的位置。

This is what I'm using so far to show my location.

    Location location = locationManager
                    .getLastKnownLocation(bestProvider);
            try {

                GeoPoint myPoint2 = new GeoPoint(
                        (int) (location.getLatitude() * 1E6),
                        (int) (location.getLongitude() * 1E6));
                newoverlay.drawMyLocation(null, mapView, location, myPoint2,
                        1000);
                mapOverlays.add(newoverlay);
            } catch (NullPointerException e) {
                GeoPoint myPoint2 = new GeoPoint((int) (-1 * 1E6),
                        (int) (-1 * 1E6));
                **newoverlay.drawMyLocation(null, mapView, location, myPoint2,
                        1000);**
                mapOverlays.add(newoverlay);
            }

我不知道该用什么作为画布,所以我把它与空,因此它会编译。我使用的是从一个位置管理器中的位置,我从位置变量我的GeoPoint。我也不能确定是什么时,参数被认为是。

I'm not sure what to put as the Canvas so I placed it with null so that it would compile. I'm using the location from a location Manager and I have my geopoint from the location variable. I'm also unsure what the "when" parameter is supposed to be.

我也想知道如何蓝泡泡知道移动的人,是否图像更新每隔x毫秒根据何时参数?

I was also wondering how the blue bubble knows to move with the person, does the picture update every x milliseconds depending on the "when" parameter?

到目前为止,该应用程序没有崩溃,但它也没有显示蓝点的任何位置。 我敢肯定,我只需要和发现什么帆布参数应该有所帮助。

So far the app isn't crashing, but it is also not showing the blue dot at any location. I'm sure I just need help with finding what the canvas parameter should be.

感谢

推荐答案

尝试这种方式在地图中活动

try this way in your map activity

class CurOverlay extends Overlay {
        private GeoPoint pointToDraw;

        public void setPointToDraw(GeoPoint point) {
            pointToDraw = point;
        }

        public GeoPoint getPointToDraw() {
            return pointToDraw;
        }

        @Override
        public boolean draw(Canvas canvas, MapView curmapView, boolean shadow,
                long when) {
            super.draw(canvas, curmapView, shadow);

            // convert point to pixels
            Point screenPts = new Point();
            curmapView.getProjection().toPixels(pointToDraw, screenPts);

            // add marker
            Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                    R.drawable.pinsource);
            canvas.drawBitmap(bmp, screenPts.x - 28, screenPts.y - 48, null);
            return true;
        }

    }

我希望这会为你工作。

i hope this will work for you.

这篇关于如何正确使用drawMyLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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