用户移动时如何在android中更改Google地图的图钉?

时间:2011-09-06 05:52:28

标签: android google-maps geolocation

在我的Android应用中,我需要在Google地图中显示用户的当前位置。我可以在onLocationChange()方法中更改地图。但问题是我也想更换引脚。当用户继续前进时,如何移动引脚?

提前致谢!

2 个答案:

答案 0 :(得分:1)

您需要将lat / lng传递给MapActivity类,然后将其设置到GeoPoint对象中。您还可以在地图中添加叠加(当您第一次在地图上显示图钉时添加一次),并且在通过叠加层实现的那个类中,您必须绘制针点并在其中传递GeoPoint对象

private void drawFreeMarker(Canvas canvas, MapView mapView, boolean shadow) {
            Point screenPts = new Point();
            mapView.getProjection().toPixels(tempPoint, screenPts);
            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bluepin_38);
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
        }

这里我在我的应用程序中以这种方式实现tempPoint是包含lat / lng值的GeoPoint,当位置发生变化时,你必须将该值传递给MapActivity并使地图无效,这样你就可以移动你的销

答案 1 :(得分:0)

您需要onLocationChanged从mapView previus overlay中删除并使用标记添加第二个...我假设您正在使用My Location Overlay类????