gpt4 book ai didi

java - Android:这里 map sdk的 map 显示的坐标不准确

转载 作者:行者123 更新时间:2023-12-01 16:47:37 25 4
gpt4 key购买 nike

我在我的项目中使用 HERE Maps Lite SDK for Android 作为库。我想显示 MapView,并添加数据库中所有避难所的覆盖图及其特定坐标。 map 运行良好,但显示的坐标不准确。我尝试对经纬度网站中的坐标进行地理编码,它们是正确的,但在 map 中它们显示在其真实位置的右侧。

我的代码:

 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shelters_map);
mapView = findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
ActivityCompat.requestPermissions(SheltersMapActivity.this, new String[] {
Manifest.permission.ACCESS_FINE_LOCATION}, 123);
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
Toast.makeText(getApplicationContext(), "אנא אפשר גישה לשירותי מיקום", Toast.LENGTH_SHORT).show();
ActivityCompat.requestPermissions(this,
new String[]{ACCESS_FINE_LOCATION},
1);
} else // premission is granted
{
GPStracker g = new GPStracker(getApplicationContext());
userLocation = g.getLocation();
}
loadMapScene();
addSheltersOverlay();
// loadMapScene();


}

private void loadMapScene() {
// Load a scene from the SDK to render the map with a map style.
mapView.getMapScene().loadScene(MapStyle.NORMAL_DAY, new MapScene.LoadSceneCallback() {
@Override
public void onLoadScene(@Nullable MapScene.ErrorCode errorCode) {
if (errorCode == null) {
mapView.getCamera().setTarget(new GeoCoordinates(userLocation.getLatitude(),
userLocation.getLongitude()));
mapView.getCamera().setZoomLevel(15);
} else {
Log.d("data1", "onLoadScene failed: " + errorCode.toString());
}
}
});
}

private void addSheltersOverlay() {
db = new DatabaseHandler(this);
ArrayList<Shelter> places = this.db.getAllPlaces();
Shelter userLocationPlace = new Shelter("המיקום שלך", "", userLocation, null, 0, "");
places.add(userLocationPlace);
int size = places.size();
for(int i = 0; i < size; i++) {
TextView textView = new TextView(this);
textView.setTextColor(Color.parseColor("#FFFFFF"));
textView.setText(places.get(i).getName());

LinearLayout linearLayout = new LinearLayout(this);
if (places.get(i) instanceof Basement)
linearLayout.setBackgroundColor(Color.BLACK);
else if (places.get(i) instanceof Stairs)
linearLayout.setBackgroundColor(Color.GREEN);
else
linearLayout.setBackgroundColor(Color.BLUE);
linearLayout.setPadding(10, 10, 10, 10);
linearLayout.addView(textView);

GeoCoordinates geoCoordinates = new GeoCoordinates(places.get(i).getLocation().getLatitude(),
places.get(i).getLocation().getLongitude());
MapOverlay<LinearLayout> mapOverlay = new MapOverlay<>(linearLayout, geoCoordinates);

mapView.addMapOverlay(mapOverlay);
}
}

显示的 map :

Screenshot of the map .

我可以在显示的 map 本身中看到街道名称,但我发现这不是准确的点。有人帮忙吗?

最佳答案

从代码来看,它看起来是正确的,但我看不到该位置与预期位置。默认情况下,MapOverlays 是以坐标为中心绘制的。您可以设置 anchor 来相对于坐标移动叠加层。如果数据库中的坐标与 map 上的位置之间始终存在偏移,这可能会有所帮助。

也许,您可以尝试将一个小的 MapCircle 项目渲染到 map 上的预期位置吗?然后您可以更轻松地查看该位置在 map 上的位置。您可以将结果与 https://www.latlong.net/ 进行比较.

关于java - Android:这里 map sdk的 map 显示的坐标不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61745107/

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