[英]Here SDK mark position on map
我在 map 上顯示用戶的 position 但我想做的是標記相同
在 onCreate 我得到用戶的 position:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get a MapView instance from layout
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
latitud=location.getLatitude();
longitud=location.getLongitude();
mapView = findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
handleAndroidPermissions();
}
那么我在加載map的時候想要做的就是顯示出來並打個記號,我是這樣做的:
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) {
mapObjectsExample = new MapObjectsExample(mapView);
GeoCoordinates geoCoordinates=new GeoCoordinates( latitud,longitud);
MapImage mapImage = MapImageFactory.fromResource(getApplicationContext().getResources(), R.drawable.here_car);
MapMarker mapMarker = new MapMarker( geoCoordinates, mapImage);
mapView.getMapScene().addMapMarker(mapMarker);
mapView.getCamera().setTarget(new GeoCoordinates( latitud,longitud));
mapView.getCamera().setZoomLevel(15);
} else {
Log.d(TAG, "onLoadScene failed: " + errorCode.toString());
}
}
});
}
但我得到:
MapMarker(long, java.lang.Object)' 在 'com.here.sdk.mapviewlite.MapMarker' 中具有受保護的訪問權限
問題出在這句話中:
MapMarker mapMarker = new MapMarker( geoCoordinates, mapImage);
在 lite Product Variant 中,我們不能將圖像 Object 直接傳遞給 MapMarker 構造函數。下面是我們如何在 lite Variant 中使用圖像標記的代碼片段。 github 示例中涵蓋了相同的內容。
Github 鏈接: https://github.com/heremaps/here-sdk-examples/tree/master/examples/latest/lite/android/MapMarkerLite
MapImage mapImage = MapImageFactory.fromResource(context.getResources(), R.drawable.here_car);
MapMarker mapMarker = new MapMarker(geoCoordinates);
mapMarker.addImage(mapImage, new MapMarkerImageStyle());
mapView.getMapScene().addMapMarker(mapMarker);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.