android离线天地图,天地图的移动App开发,离线地图下载不了[亲测有效]

android离线天地图,天地图的移动App开发,离线地图下载不了[亲测有效]该楼层疑似违规已被系统折叠隐藏此楼查看此楼求大神帮忙看下,谢谢,这是天地图官网的源代码:001packagesdkdemo.com;002003importjava.util.ArrayList;004importjava.util.Timer;005importjava.util.TimerTask;006007importandroid.app.Activity;008…

大家好,欢迎来到IT知识分享网。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

求大神帮忙看下,谢谢,这是天地图官网的源代码:

001 package sdkdemo.com;

002

003 import java.util.ArrayList;

004 import java.util.Timer;

005 import java.util.TimerTask;

006

007 import android.app.Activity;

008 import android.app.ProgressDialog;

009 import android.os.Bundle;

010 import android.os.Handler;

011 import android.os.Message;

012 import android.view.View;

013 import android.view.View.OnClickListener;

014 import android.widget.Button;

015 import android.widget.EditText;

016 import android.widget.ProgressBar;

017 import android.widget.Toast;

018

019 import com.tianditu.android.maps.GeoPoint;

020 import com.tianditu.android.maps.MapController;

021 import com.tianditu.android.maps.MapView;

022 import com.tianditu.android.maps.TErrorCode;

023 import com.tianditu.android.maps.MapView.TMapType;

024 import com.tianditu.android.maps.TOfflineMapInfo;

025 import com.tianditu.android.maps.TOfflineMapManager;

026 import com.tianditu.android.maps.TOfflineMapManager.City;

027 import com.tianditu.android.maps.TOfflineMapManager.MapAdminSet;

028 import com.tianditu.android.maps.TOfflineMapManager.OnGetMapsResult;

029

030 public class OfflineMapDemo extends Activity implements OnGetMapsResult{

031 private MapView mMapView = null;

032 private TOfflineMapManager offlineMapMng= null;

033 private ProgressBar mPb = null;

034 private Handler mUpdateHandler = null;

035 private ProgressDialog mDlg = null;

036 private MapController mController = null;

037 private ArrayList mAllMaps = null; //所有的地图相关数据

038 private Timer mTimer = null;

039 private TimerTask mTimerTask = null;

040

041 @Override

042 protected void onCreate(Bundle savedInstanceState) {

043 // TODO Auto-generated method stub

044 super.onCreate(savedInstanceState);

045 setContentView(R.layout.offlinemapdemo);

046 offlineMapMng = new TOfflineMapManager(this);

047 offlineMapMng.setMapPath(“/sdcard/tianditu3/staticmap/”);

048 mMapView = (MapView)findViewById(R.id.offlinemap_mapview);

049 mMapView.setCachePath(“/sdcard/tianditu/map/”);

050 mController = mMapView.getController();

051 mController.setZoom(10);

052 mController.animateTo(new GeoPoint(39665124,116065124));

053 offlineMapMng.getMapList();

054 mMapView.setOfflineMaps(offlineMapMng.searchLocalMaps());

055

056 final EditText etCity = (EditText)findViewById(R.id.offlinemap_et_city);

057 Button btn = (Button)findViewById(R.id.offlinemap_btn_start);

058

059 btn.setOnClickListener(new OnClickListener(){

060

061 @Override

062 public void onClick(View view) {

063 // TODO Auto-generated method stub

064 mPb.setVisibility(View.VISIBLE);

065 offlineMapMng.startDownload(etCity.getText().toString(), TMapType.MAP_TYPE_VEC);

066 mTimer = new Timer();

067 mTimerTask = new TimerTask(){

068

069 @Override

070 public void run() {

071 // TODO Auto-generated method stub

072 Message msg = mUpdateHandler.obtainMessage();

073 msg.what = 1;

074 mUpdateHandler.dispatchMessage(msg);

075 }};

076 mTimer.schedule(mTimerTask, 0, 1000);

077 }

078 });

079

080 btn = (Button)findViewById(R.id.offlinemap_btn_pause);

081 btn.setOnClickListener(new OnClickListener(){

082

083 @Override

084 public void onClick(View view) {

085 // TODO Auto-generated method stub

086 offlineMapMng.pauseDownload();

087 if(mTimerTask != null)

088 mTimerTask.cancel();

089 mTimerTask = null;

090 if(mTimer != null)

091 mTimer.cancel();

092 mTimer = null;

093 ArrayList infos = offlineMapMng.getPausedMaps();

094 if(infos == null){

095 return;

096 }

097

098 }

099

100 });

101

102 mUpdateHandler = new Handler(){

103

104 @Override

105 public void handleMessage(Message msg) {

106 // TODO Auto-generated method stub

107 switch(msg.what)

108 {

109 case 1:

110 TOfflineMapInfo info = offlineMapMng.getDownloadInfo(etCity.getText().toString(), TMapType.MAP_TYPE_VEC);

111 if(info != null)

112 mPb.setProgress(info.getDownloadedSize()*100/info.getSize());

113 if(info == null || info.getState() != TOfflineMapManager.OFFLINEMAP_DOWNLOADING)

114 {

115 return;

116 }

117

118 //处理下载完成

119 if(info.getState() == TOfflineMapManager.OFFLINEMAP_DOWNLOAD_FINISHED)

120 {

121 mMapView.setOfflineMaps(offlineMapMng.searchLocalMaps());

122 }

123 break;

124

125 }

126

127 }

128

129 };

130 mPb = (ProgressBar)findViewById(R.id.offlinemap_progress);

131

132 mDlg = new ProgressDialog( this);

133 mDlg.setTitle( “天地图” );

134 mDlg.setProgressStyle( ProgressDialog.STYLE_SPINNER );

135 mDlg.setMessage( “正在初始化…” );

136 mDlg.setCanceledOnTouchOutside( false );

137 mDlg.setCancelable( true );

138 mDlg.show();

139 if(mAllMaps == null)

140 offlineMapMng.getMapList();

141

142 }

143

144 @Override

145 public void onGetResult(ArrayList maps, int error) {

146 // TODO Auto-generated method stub

147 mDlg.dismiss();

148 if(error != TErrorCode.OK)

149 return;

150 mAllMaps = maps;

151 int size = maps.size();

152 String str = “”;

153 for(int i = 0;i < size;i++){

154 MapAdminSet adminSet = maps.get(i);

155 str += adminSet.getName();

156 ArrayList citys = adminSet.getCitys();

157 str += “城市:”;

158 for(int k=0; k

159 {

160 str += citys.get(k).getName() + ” “;

161 }

162 str += “\n”;

163 }

164 Toast.makeText(OfflineMapDemo.this, str, Toast.LENGTH_SHORT).show();

165 }

166

167 }

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/13637.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信