Java ME guide bee map development example: offline map example

Source: Internet
Author: User

On the mobile phone, the offline map package is usually placed on the SD card and then read through the file. For the sake of simplicity, put offline in the Resource Directory of the example and compile it with the application. In actual applications, store these map packages separately. The Guide bee map development kit supports reading multiple map packages at the same time. This is done through the MapTiledZone class and MapTileStreamReader class. Each map package corresponds to a MapTiledZone. The map Package creates an index for each map to accelerate Image Retrieval. The location and zoom level of the map package are recorded. MapTileStreamReader provides methods for managing these map packages.

[Java]
//------------------------------------------------------------------------------
// COPYRIGHT 2010 GUIDEBEE
// All rights reserved.
// GUIDEBEE CONFIDENTIAL PROPRIETARY
/// // REVISIONS // //////////////////////////////
// Date Name Tracking # Description
//----------------------------------------------------------------
// 16SEP2010 James Shen Initial Creation
//////////////////////////////////////// ////////////////////////////////////////
// ----------------------------------- PACKAGE ------------------------------------
Package com. pstreets. gisengine. demo. midp;

// ------------------------------------- IMPORTS ------------------------------------
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. raster. MapTileStreamReader;
Import com. mapdigit. gis. raster. MapTiledZone;
Import com. mapdigit. gis. raster. MapType;
Import com. pstreets. gisengine. demo. MapDemoMIDP;
Import java. io. ByteArrayInputStream;
Import java. io. DataInputStream;
Import java. io. IOException;
Import java. io. InputStream;
Import javax. microedition. lcdui. Display;

// [-------------------------------- Main class ----------------------------------]
// ----------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
//------------------------------------------------------------------
// 16SEP2010 James Shen Initial Creation
//////////////////////////////////////// ////////////////////////////////////////
/**
* Stored map demo for Guidebee Map API on MIDP platform.
* <Hr> <B>©Copyright 2010 Guidebee, Inc. All Rights Reserved. </B>
* @ Version 1.00, 16/09/10
* @ Author Guidebee Pty Ltd.
*/
Public class StoredMapMIDP extends MapDemoMIDP {

MapTileStreamReader localMapTileFileReader;

Public void startApp (){

Init ();

InputStream is = this. getClass (). getResourceAsStream ("/world03.map ");
Byte [] buffer = null;
Try {
Buffer = new byte [is. available ()];
Is. read (buffer );
Is. close ();
} Catch (IOException ex ){
Ex. printStackTrace ();
}
ByteArrayInputStream bais = new ByteArrayInputStream (buffer );
MapTiledZone mapTiledZone = new MapTiledZone (new DataInputStream (bais ));

LocalMapTileFileReader
= MapTileDownloadManager. getInteralMapTileStreamReader ();
LocalMapTileFileReader. addZone (mapTiledZone );
// You can add more store map package here use addZone

LocalMapTileFileReader. open ();
GeoLatLng center = new GeoLatLng (-31.948275, 115.857562 );
Map. setCenter (center, 3, MapType. GOOGLEMAP );
Display. getDisplay (this). setCurrent (canvas );
}

Public void destroyApp (boolean unconditional ){
LocalMapTileFileReader. close ();
}
}
//------------------------------------------------------------------------------
// COPYRIGHT 2010 GUIDEBEE
// All rights reserved.
// GUIDEBEE CONFIDENTIAL PROPRIETARY
/// // REVISIONS // //////////////////////////////
// Date Name Tracking # Description
//----------------------------------------------------------------
// 16SEP2010 James Shen Initial Creation
//////////////////////////////////////// ////////////////////////////////////////
// ----------------------------------- PACKAGE ------------------------------------
Package com. pstreets. gisengine. demo. midp;
 
// ------------------------------------- IMPORTS ------------------------------------
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. raster. MapTileStreamReader;
Import com. mapdigit. gis. raster. MapTiledZone;
Import com. mapdigit. gis. raster. MapType;
Import com. pstreets. gisengine. demo. MapDemoMIDP;
Import java. io. ByteArrayInputStream;
Import java. io. DataInputStream;
Import java. io. IOException;
Import java. io. InputStream;
Import javax. microedition. lcdui. Display;
 
// [-------------------------------- Main class ----------------------------------]
// ----------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
//------------------------------------------------------------------
// 16SEP2010 James Shen Initial Creation
//////////////////////////////////////// ////////////////////////////////////////
/**
* Stored map demo for Guidebee Map API on MIDP platform.
* <Hr> <B>©Copyright 2010 Guidebee, Inc. All Rights Reserved. </B>
* @ Version 1.00, 16/09/10
* @ Author Guidebee Pty Ltd.
*/
Public class StoredMapMIDP extends MapDemoMIDP {
 
MapTileStreamReader localMapTileFileReader;
 
Public void startApp (){
 
Init ();
 
InputStream is = this. getClass (). getResourceAsStream ("/world03.map ");
Byte [] buffer = null;
Try {
Buffer = new byte [is. available ()];
Is. read (buffer );
Is. close ();
} Catch (IOException ex ){
Ex. printStackTrace ();
}
ByteArrayInputStream bais = new ByteArrayInputStream (buffer );
MapTiledZone mapTiledZone = new MapTiledZone (new DataInputStream (bais ));
 
LocalMapTileFileReader
= MapTileDownloadManager. getInteralMapTileStreamReader ();
LocalMapTileFileReader. addZone (mapTiledZone );
// You can add more store map package here use addZone
 
LocalMapTileFileReader. open ();
GeoLatLng center = new GeoLatLng (-31.948275, 115.857562 );
Map. setCenter (center, 3, MapType. GOOGLEMAP );
Display. getDisplay (this). setCurrent (canvas );
}
 
Public void destroyApp (boolean unconditional ){
LocalMapTileFileReader. close ();
}
}

 

 

World03.map stores world maps 1-4. MapTileManager internally defines a MapTileStreamReader. If a local map is set, MapTileManager reads the data locally. If no image is needed locally, it downloads the data from the map server. You can use the addZone method of MapTileStreamReader to add multiple map packages. The map packages can have overlapping areas. The order of addition affects the results. If there are multiple map packages, the first one is used.

Author: mapdigit

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.