我试图用android中的默认蓝点显示用户的当前位置。在我的地图页面中,我也有一个显示不同兴趣点的布局。我在找出如何处理一些变量时遇到了麻烦,不知道是否有人可以帮助我。
这就是我到目前为止用来显示我的位置的。
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);
}
我不确定要放什么作为画布,所以我把它放入null,这样它就可以编译了。我使用来自位置管理器的位置,并从位置变量获得我的地理位置。我也不确定"when“参数应该是什么。
我还想知道蓝色气泡是如何知道与人一起移动的,图片是否每x毫秒更新一次,取决于“何时”参数?
到目前为止,该应用程序没有崩溃,但它也没有在任何位置显示蓝点。我确信我只是需要帮助来找出画布参数应该是什么。
谢谢
发布于 2011-09-01 15:23:07
在地图活动中尝试此方法
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;
}
}
我希望这对你有用。
https://stackoverflow.com/questions/7267077
复制相似问题