Pra*_*tik 16 android google-maps
我正在开发Android应用程序,我完全是新手.所以我想知道如何在地图中显示标记以及如何在特定时间更改其位置,例如在背景中定义线程或任何将发送经度和纬度值的标记,并且标记在此处移动
Pēt*_*une 17
如果您要显示一个项目,MapView.addView()稍后更新位置setLayoutParams就可以了.
private ImageView mCurrentPointer;
@Override
public void onLocationChanged(Location l) {
int latitude = (int) (l.getLatitude() * 1e6);
int longitude = (int) (l.getLongitude() * 1e6);
// Prepare new LayoutParams object that centers on our new latitude/longitude
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, new GeoPoint(latitude, longitude),
MapView.LayoutParams.CENTER);
if (mCurrentPointer == null) {
// If "current location" pin is null, we haven't added it
// to MapView yet. So instantiate it and add it to MapView:
mCurrentPointer = new ImageView(this);
mCurrentPointer.setImageResource(R.drawable.ic_maps_indicator_current_position);
mMapView.addView(mCurrentPointer, lp);
} else {
// If it's already added, just update its location
mCurrentPointer.setLayoutParams(lp);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15912 次 |
| 最近记录: |