Android:此处sdk的地图显示的坐标不准确

问题描述 投票:0回答:1

我正在将HERE Maps Lite SDK(Android版)用作我项目中的库。我想显示MapView,并在其数据库中以特定坐标添加我在数据库中拥有的所有掩体的覆盖图。该地图效果很好,但显示的坐标不正确。我试图对经纬度网站中的坐标进行地理编码,虽然它们是正确的,但是在地图中显示的是它们的真实位置。

我的代码:

 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);
        }
    }

显示的地图:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9mUmJLby5wbmcifQ==” alt =“地图的截图”>。

我可以在显示的地图中看到街道名称,我发现这不是准确的位置。有人帮忙吗?

java android here-api
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.