When mapview is used in Google map Android API V2, cameraupdatefactory is not initialized! Solution

Source: Internet
Author: User

Let's talk about the map V2 API key first:

During app packaging, You need to generate a XXX. keystore and use the sha1 generated by this secret room library to apply for the key as the key in androidmanifest. xml.

(Sometimes the key generated using Debug. keystore can also be used for unknown reasons)

Enter the subject:

According to https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory? Hl = ZH-CN description,

Cameraupdatefactorypublic final class Cameraupdatefactory

A class containing methods for creatingCameraUpdateObjects
That change a map's camera. to modify the map's camera, callanimateCamera(CameraUpdate),animateCamera(CameraUpdate,
GoogleMap.CancelableCallback)
OrmoveCamera(CameraUpdate),
UsingCameraUpdateObject
Created with this class.

For example, to zoom in on a map, you can use the following 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 forGoogleMapTo
    Become available fromMapFragmentOrMapViewThat
    You have added to your application. You can verify thatGoogleMapIs
    Available by callinggetMap()Method and checking that the returned object is
    Not null.
  • Callinitialize(Context).
    As long as a com. Google. Android. GMS. Common. googleplayservicesnotavailableexception isn' t thrown, this class will be correctly initialized.

That is, initializationCameraupdatefactoryNeed to ensure

1. The GoogleMap object is not empty.

2. initialize mapsinitializer. initialize (context ).

Therefore, if the GoogleMap object is excluded as null, you only need to call mapsinitializer. initialize (context) before cameraupdatefactory to initialize the object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.