Android引路蜂地图开发示例:地图平移

RasterMap 有两个方法可以用于平移地图,panTo 将地图移动到指定经纬度坐标,panDirection(dx,dy) 将地图从当前位置平移dx,dy 个象素。
GuidebeeMapView实现了对TouchEvent处理,可以通过Touch事件来平移地图,下列示例是通过菜单来以上,下,左,右平移地图。

package com.pstreets.gisengine.demo;
 
import com.mapdigit.gis.geometry.GeoLatLng;
import com.pstreets.gisengine.R;
import com.pstreets.gisengine.SharedMapInstance;
import com.mapdigit.gis.raster.MapType;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
 
public class MapPan extends Activity {
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 }
 
 @Override
 public void onStart() {
  super.onStart();
  GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);
  SharedMapInstance.map.setCenter(center, 13, MapType.MICROSOFTCHINA);
 
 }
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.mappan_menu, menu);
  return true;
 }
 
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle item selection
  switch (item.getItemId()) {
  case R.id.mapup:
   SharedMapInstance.map.panDirection(0, -32);
   return true;
  case R.id.mapdown:
   SharedMapInstance.map.panDirection(0, 32);
   return true;
  case R.id.mapleft:
   SharedMapInstance.map.panDirection(-32, 0);
   return true;
  case R.id.mapright:
   SharedMapInstance.map.panDirection(32, 0);
   return true;
 
  default:
   return super.onOptionsItemSelected(item);
  }
 
 }
 
}

Android引路蜂地图开发包Ver2.1下载

你可能感兴趣的:(android)