gpt4 book ai didi

android - 如何使用标记在android中显示 map

转载 作者:IT老高 更新时间:2023-10-28 23:33:27 26 4
gpt4 key购买 nike

我正在开发 android 应用程序,我在这方面完全是新手。所以我想知道如何在 map 中显示标记以及如何在特定时间更改他的位置,例如定义线程或背景中将发送纬度和经度值的任何内容,并且标记在此移动

最佳答案

如果您只想显示一个项目,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);
}
}

关于android - 如何使用标记在android中显示 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6140433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com