歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android自定義地圖示例:QQ地圖

Android自定義地圖示例:QQ地圖

日期:2017/3/1 10:17:36   编辑:Linux編程
來一個簡單一些的自定義地圖類型示例:QQ地圖,QQ地圖URL規則比較簡單。1-17級都是有一層組成,選用GENERIC_MAPTYPE_5作為QQ地圖類型,直接在CustomMap修改代碼如下:
  1. package com.pstreets.gisengine.demo;
  2. import com.mapdigit.gis.raster.ICustomMapType;
  3. import com.mapdigit.gis.raster.MapType;
  4. import com.mapdigit.gis.geometry.GeoLatLng;
  5. import com.pstreets.gisengine.R;
  6. import com.pstreets.gisengine.SharedMapInstance;
  7. import Android.app.Activity;
  8. import android.os.Bundle;
  9. import android.view.Menu;
  10. import android.view.MenuInflater;
  11. import android.view.MenuItem;
  12. public class CustomMap extends Activity {
  13. @Override
  14. public void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.main);
  17. }
  18. @Override
  19. public void onStart() {
  20. super.onStart();
  21. MapType.setCustomMapTileUrl(new TiandiMapType());
  22. GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
  23. SharedMapInstance.map.setCenter(center, 13, MapType.GENERIC_MAPTYPE_5);
  24. }
  25. @Override
  26. public boolean onCreateOptionsMenu(Menu menu) {
  27. MenuInflater inflater = getMenuInflater();
  28. inflater.inflate(R.menu.mapzoom_menu, menu);
  29. return true;
  30. }
  31. @Override
  32. public boolean onOptionsItemSelected(MenuItem item) {
  33. // Handle item selection
  34. switch (item.getItemId()) {
  35. case R.id.zoomin:
  36. SharedMapInstance.map.zoomIn();
  37. return true;
  38. case R.id.zoomout:
  39. SharedMapInstance.map.zoomOut();
  40. return true;
  41. default:
  42. return super.onOptionsItemSelected(item);
  43. }
  44. }
  45. }
  46. class TiandiMapType implements ICustomMapType {
  47. private static int serverIndex=1;
  48. public String getTileURL(int mtype, int x, int y, int zoomLevel) {
  49. String returnURL="";
  50. serverIndex+=1;
  51. serverIndex%=3;
  52. int maxTiles=(int)Math.pow(2, zoomLevel);
  53. switch(mtype){
  54. case MapType.GENERIC_MAPTYPE_5:
  55. returnURL= "http://p"
  56. + serverIndex+".map.qq.com/maptiles/" ;
  57. y=maxTiles-y-1;
  58. returnURL+=+zoomLevel
  59. +"/"+(int)(x/16)+"/"+(int)(y/16)+"/"+x+"_"+y+".gif";
  60. break;
  61. case MapType.GENERIC_MAPTYPE_6:
  62. if(zoomLevel<11){
  63. returnURL= "http://tile"
  64. + serverIndex+".tianditu.com/DataServer?T=A0512_EMap";
  65. returnURL+="&X="+x+"&Y="+y+"&L="+zoomLevel;
  66. }else if(zoomLevel<13){
  67. returnURL= "http://tile"
  68. + serverIndex+".tianditu.com/DataServer?T=B0627_EMap1112";
  69. returnURL+="&X="+x+"&Y="+y+"&L="+zoomLevel;
  70. }else{
  71. returnURL= "http://tile"
  72. + serverIndex+".tianditu.com/DataServer?T=siwei0608";
  73. returnURL+="&X="+x+"&Y="+y+"&L="+zoomLevel;
  74. }
  75. break;
  76. case MapType.GENERIC_MAPTYPE_7:
  77. if(zoomLevel<11){
  78. returnURL= "http://tile"
  79. + serverIndex+".tianditu.com/DataServer?T=AB0512_Anno";
  80. returnURL+="&X="+x+"&Y="+y+"&L="+zoomLevel;
  81. }else{
  82. returnURL=MapType.EMPTY_TILE_URL;
  83. }
  84. break;
  85. }
  86. return returnURL;
  87. }
  88. }

QQ地圖的分片方法和Google中國地圖分片方法一致,經緯度坐標無需調整。

Copyright © Linux教程網 All Rights Reserved