如何解决这里SDK在地图上标记位置
在 onCreate 我得到用户的位置:
@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,this);
Location location = locationManager.getLastKNownLocation(LocationManager.GPS_PROVIDER);
latitud=location.getLatitude();
longitud=location.getLongitude();
mapView = findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
handleAndroidPermissions();
}
那么我在加载地图的时候想做的就是显示出来并做个标记,我是这样做的:
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 中,我们无法将图像对象直接传递给 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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。