To display Google Maps on the android client, you need to use Google's API. This time, Google is directly used instead of the android SDK. Because there is no detail, how many differences are there between them, it is not clear yet. Wait for a while and take a closer look. The view shown on the map is:Com. google. android. maps. if mapview is to be used, you have to apply for a map key from Google. I will not elaborate on how to apply for a map key here, but I personally feel that if it is a test, you can find a key without knowing what the difference is.
After the preceding steps are completed, because the map uses a network, you must have the network access permission, which must be added. Otherwise, the map information cannot be obtained.
The following is the implementationCode:
First, define the map controller:
PrivateMapcontroller;
PrivateGeopoint; // This indicates that the positioning center is implemented in the code.
Then we can implement it!
The following is the implementation code:
Code
Setcontentview (R. layout. Main );
Mapview = (Mapview) findviewbyid (R. Id. mapview1 );
Mapcontroller = Mapview. getcontroller ();
Mapview. setenabled ( True );
Mapview. setclickable ( True );
Mapview. setbuiltinzoomcontrols ( True );
Geopoint = New Geopoint (( Int ) 40.9166666666667 * 1000000 ,( Int ) 116.816666666667 * 1000000 );
Mapcontroller. animateto (geopoint );
Mapcontroller. setzoom ( 12 );
If you want to display information at a certain point, you can use the following function to set it:
Code
Class Mylocationoverlay Extends Overlay
{
@ Override
Public Boolean Draw (canvas, mapview, Boolean Shadow, Long When)
{
Super . Draw (canvas, mapview, shadow );
Paint paint = New Paint ();
Point myscreencoords = New Point ();
// Convert longitude and latitude to actual screen coordinates
Mapview. getprojection (). topixels (geopoint, myscreencoords );
Paint. setstrokewidth ( 1 );
Paint. setargb ( 255 , 255 , 0 , 0 );
Paint. setstyle (paint. style. Stroke );
Bitmap BMP = Bitmapfactory. decoderesource (getresources (), R. drawable. Home );
Canvas. drawbitmap (BMP, myscreencoords. X, myscreencoords. Y, paint );
Canvas. drawtext ( " Name to be displayed " , Myscreencoords. X, myscreencoords. Y, paint );
Return True ;
}
}
Of course, to display a map, if we inherit activity, it cannot be displayed, so we need to change it to mapactivity, which is why we need to use Google API!
All right, this map, combined with the GPS information described above, has been achieved, and then the following can be achieved through GPS positioning, in fact, you only need to combine the two of them to achieve positioning!