在使用 BaiduMap.getProjection() 的时候出现空指针。看了官方文档才知道,要在setOnMapLoadedCallback() 中使用就不会出现空指针问题
mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
int[] location = new int[2];
locationMapview.getLocationOnScreen(location);
Point p = new Point((locationMapview.getWidth() / 2) + location[0], (locationMapview.getHeight() / 2) + location[1]);
LatLng latLng = mBaiduMap.getProjection().fromScreenLocation(p);
Log.d("--->", "onMapStatusChangeFinish: "+ (mBaiduMap.getProjection()==null));
selectedMarkers.setX((locationMapview.getWidth() / 2) + location[0]);
selectedMarkers.setY((locationMapview.getHeight() / 2) + location[1]);
//0.0000310787136
//0.00003898647009
latitude = latLng.latitude;
longitude = latLng.longitude;
Log.i("location", latLng.longitude + "," + latLng.latitude);
selectedMarkers.setAnimation(pointTransformation());
mSearch.reverseGeoCode(new ReverseGeoCodeOption().location(latLng).newVersion(1).radius(200));
}
});