谷歌地图CameraUpdateFactory未初始化 [英] Google Maps CameraUpdateFactory not initialized
问题描述
我收到了一些报告,从用户体验的背透crashlytics给我一个错误
I'm getting some reports back from user experience through crashlytics giving me an error
Fatal Exception java.lang.NullPointerException
CameraUpdateFactory is not initialized
这是不是一个经常性的死机,因为它不发生的每一个用户,但它变得太普通,我需要解决这个问题。
This is not a regular crash, as in it doesn't occur for every user but it is becoming too regular and I need to resolve it.
我读了,这可能发生,如果地图还没有被初始化,我认为我已经介绍
I had read that this could happen if the maps hadn't been initialized which I think I've covered
if(googleMap!=null){
googleMap.animateCamera(CameraUpdateFactory.newLatLng(selectedLatLng));
}
也有可能原因可能是谷歌播放服务是不是在设备上或者是过时的,我已经添加了一些验证为也。
also a probably cause could be that google play services isn't on the device or is out of date and I've added some verification for that also.
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(FuelsFragment.this.getActivity());
// Showing status
//CAMERAUPDATE FACTORY CRASH CAN BE A RESULT OF GOOGLE PLAY SERVICES NOT INSTALLED OR OUT OF DATE
//ADDITIONAL VERIFICATION ADDED TO PREVENT FURTHER CRASHES
//https://github.com/imhotep/MapKit/pull/17
if(status == ConnectionResult.SUCCESS)
{
mMapFragment = ReepMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.mapContainer, mMapFragment);
fragmentTransaction.commit();
}
else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
reep.toastNotify("You need to update Google Play Services in order to view maps");
}
else if (status==ConnectionResult.SERVICE_MISSING){
reep.toastNotify("Google Play service is not enabled on this device.");
}
在这我不能确定下一步怎么做,因为这不会发生为每个用户。
After that I'm unsure what next to do as this doesn't happen for each user.
如果任何人有会出现这种情况我倒是AP preciate有什么想法你输入
If anyone has any thoughts on why this occurs I'd appreciate your input
推荐答案
我得到了同样的错误,即使我得到来自MapView的一个非空的GoogleMap对象。我决定用它来MapsInitializer的显式调用,即使文件说,这是没有必要的。
I was getting the same error, even though I obtained a non-null GoogleMap object from a MapView. I resolved it with an explicit call to MapsInitializer, even though the documentation says it's not needed.
我的应用程序的片段通过以下设置的MapView:
My app's Fragment sets up the MapView via the following:
@Override public View
onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.map_panel, container, false);
mapView = (MapView) view.findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
configureMap(mapView.getMap());
return view;
}
private void
configureMap(GoogleMap map, double lat, double lon)
{
if (map == null)
return; // Google Maps not available
try {
MapsInitializer.initialize(getActivity());
}
catch (GooglePlayServicesNotAvailableException e) {
Log.e(LOG_TAG, "Have GoogleMap but then error", e);
return;
}
map.setMyLocationEnabled(true);
LatLng latLng = new LatLng(lat, lon);
CameraUpdate camera = CameraUpdateFactory.newLatLng(latLng);
map.animateCamera(camera);
}
在我加入了呼吁MapsInitializer,我会从CameraUpdateFactory异常。添加通话结束后,CameraUpdateFactory总会成功。
Before I added the call to MapsInitializer, I would get an exception from CameraUpdateFactory. After adding the call, CameraUpdateFactory always succeeds.
这篇关于谷歌地图CameraUpdateFactory未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!