Basic Android skills: positioning on a map based on GPS information

Source: Internet
Author: User

I. MapView class

  • Use the android: apiKey attribute directly in the layout to define the map api key;

  • The following methods are supported:

    • MapController getController (): gets the MapController associated with this MapView;

    • GeoPoint getMapCenter (): gets the center displayed by this MapView;

    • Int getMaxZoomLevel (): obtains the maximum zoom level supported by this MapView;

    • List GetOverlays (): obtains all Overlay information displayed on the MapView;

    • Projection getProjection (): obtains the Projection relationship between the pixel coordinate and latitude and longitude of the screen;

    • Int getZoomLevel (): gets the current zoom level of the screen;

    • SetBuilthZoomControls (boolean on): sets whether to display the built-in zoom button;

    • SetStatelite (Boolean on): sets whether to display a satellite map;

    • SetTraffic (Boolean on): sets whether to display traffic conditions;

      Ii. MapViewController class

      • Controls MapView, such as controlling map positioning to a specified position, or controlling map methods and narrowing down;

      • AnimationTo (GeoPoint point): controls the map to a specified position;

        Iii. GeoPoint class

        • Is the encapsulation of latitude and longitude;

          4. Positioning in Google Map based on longitude and latitude

          1. Obtain the MapController object corresponding to MapView;

          2. Create a GeoPoint object based on the latitude and longitude obtained by the program;

          3. Call the animationTo (GeoPoint point) method of the MapController object associated with MapView to locate the specified position;

          4. Use Overlay to draw an image at the specified position of the Map

            1. Obtains the projection relationship between the screen coordinate and the latitude and longitude coordinate of the MapView;

            2. Call the toPixels method of Projection to convert longitude and latitude to screen coordinates;

            3. Call the drawBitmap method of Canvas to draw an image at a specified position on the screen;

            4. Add Google API declarations and network permissions to the configuration file;


Related Article

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.