In the example Android Concise development Tutorial 17: Dialog Display Image We left an example drawmap () is not implemented, this example shows the online map, most of the current map server is the map to the image storage to improve response speed. The general size is 256x256 pixels. You can see the offline map download method analysis.
For example: URL http://www.mapdigit.com/guidebeemap/maptile.php?type=MICROSOFTMAP&x=7&y=4&z=14 display:
The following example accesses the Internet to download the map picture, and stitching into the map display, this method is also a guide Bee map development Package implementation of a basic principle.
Android apps access the Internet, you first need to give your application access to the Internet: Add in Androidmanifest.xml:
<uses-permission android:name= "Android.permission.INTERNET"/>
then implement Drawmap () as follows:
private void Drawmap () {
try {
Graphics2d.clear (Color.White);
Graphics2d.reset ();
for (int x= 6;x< 8; x + +)
{
for (int y= 3;y< 5; y++) {
String urlstring= "Http://www.mapdigit.com/guidebeemap";
urlstring+= "/maptile.php?type=microsoftmap";
urlstring+= "&x=" +x+ "&y=" +y+ "&z=14";
URL url= new URL (urlstring);
URLConnection connection=url.openconnection ();
HttpURLConnection httpconnection= (httpurlconnection) connection;
int Responsecode=httpconnection.getresponsecode ();
if (RESPONSECODE==HTTPURLCONNECTION.HTTP_OK) {
InputStream Stream=httpconnection.getinputstream ();
Bitmap Bitmap=bitmapfactory.decodestream (stream);
int []buffer= new int [Bitmap.getheight ()
* Bitmap.getwidth ()];
Bitmap.getpixels (buffer, 0, bitmap.getwidth (), 0, 0,
Bitmap.getwidth (), Bitmap.getheight ());
Graphics2d.drawimage (Buffer,bitmap.getwidth (),
Bitmap.getheight (), (x-6) * 256, (y-3) * 256);
}
}
}
Graphic2dview.refreshcanvas ();
catch (Exception e) {
}
}
The Internet classes in Android are primarily defined in the java.net.* and android.net.* packages. The results shown above are as follows:
The map does not show Mansi because the canvas size created by graphics2d does not create a full screen, the size created is 240x320, and if you create a full screen, you can display the map full screen.
See a full set of tutorials: http://www.bianceng.cn/OS/extra/201301/35252.htm