Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法
2013-08-16 19:01
453 查看
先说一下 Map V2 API Key 的问题吧:
在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的Key使用。
(有时候用debug.keystore生成的Key也可以,不知原因)
进入正题:
根据 https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory?hl=zh-CN 描述,
A class containing methods for creating
For example, to zoom in on a map, you can use the following code:
Prior to using any methods from this class, you must do one of the following to ensure that this class is initialized:
Wait for a
Call
即:初始化 CameraUpdateFactory 需要保证
1.GoogleMap对象不为空
2.MapsInitializer.initialize(Context) 进行初始化
因此排除GoogleMap对象为空,只需在CameraUpdateFactory 之前调用MapsInitializer.initialize(Context) 即可进行初始化。
在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的Key使用。
(有时候用debug.keystore生成的Key也可以,不知原因)
进入正题:
根据 https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory?hl=zh-CN 描述,
CameraUpdateFactory
public final class CameraUpdateFactoryA class containing methods for creating
CameraUpdateobjects that change a map's camera. To modify the map's camera, call
animateCamera(CameraUpdate),
animateCamera(CameraUpdate, GoogleMap.CancelableCallback)or
moveCamera(CameraUpdate), using a
CameraUpdateobject created with this class.
For example, to zoom in on a map, you can use the following code:
[code]GoogleMap map = ...; map.animateCamera(CameraUpdateFactory.zoomIn());
Prior to using any methods from this class, you must do one of the following to ensure that this class is initialized:
Wait for a
GoogleMapto become available from a
MapFragmentor
MapViewthat you have added to your application. You can verify that the
GoogleMapis available by calling the
getMap()method and checking that the returned object is not null.
Call
initialize(Context). As long as a com.google.android.gms.common.GooglePlayServicesNotAvailableException GooglePlayServicesNotAvailableException isn't thrown, this class will be correctly initialized.
即:初始化 CameraUpdateFactory 需要保证
1.GoogleMap对象不为空
2.MapsInitializer.initialize(Context) 进行初始化
因此排除GoogleMap对象为空,只需在CameraUpdateFactory 之前调用MapsInitializer.initialize(Context) 即可进行初始化。
相关文章推荐
- Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法
- Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法
- 在使用AndroidStudio打包apk时,遇到“xxx is not translated in xxx”错误的解决办法
- Sheet can not be presented because the view is not in a window的解决办法,和window的简单使用
- 在使用AndroidStudio打包apk时,遇到“xxx is not translated in xxx”错误的解决办法
- IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
- 使用onekey-decompile-apk遇到could not decode arsc file的解决办法
- Centos 下使用 yum 提示 This system is not registered with RHN 的解决办法
- iOS开发遇到的坑之六--使用cocopods管理第三方库时,编译出现Library not found for -lPods问题的解决办法
- Android 使用webview遇到的问题及解决办法
- iOS Whose view is not in the window hierarchy 错误的解决办法
- uploadify动态更新配置参数方法uploadifySettings()报错“updateSettings is not a function”之解决办法
- IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
- The behavior of the UICollectionViewFlowLayout is not defined because 解决办法!
- 使用Activity.isfinishing()解决java.lang.IllegalArgumentException: View not attached to window manager
- android编程中遇到的关于java.io.FileNotFoundException: /mnt/sdcard/update.zip (Permission denied)错误的原因及解决办法
- [IOS开发记录]Whose view is not in the window hierarchy 错误的解决办法
- 使用apktool工具遇到could not decode arsc file的解决办法
- java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation or earlier: class gnu.xml.dom.JAXPFactory的解决办法(图文详解)
- 关于环信EaseUI百度地图切换成高德地图时遇到的mapView.onCreate(savedInstanceState);报空指针的解决办法