Android引路蜂地图开发示例:选择地图服务
引路蜂地图服务缺省使用Google地图服务,但你也可以选择其它地图服务,比方说当Google服务离线时,您可以选择MapAbc的地图服务,另外要注意的是中国地图是有偏移的。如果想使用无偏移的中国地图,一是采用地图偏移校正算法,另外一个是使用CloudMade地图服务。
所前所述,引路蜂地图开发包在设计时将地图图片显示和地图服务两部分设计成相对独立的两部分,Google中国地图图片,Bing中国地图图片,MapAbc中国地图图片是有偏移的地图图片,CloudMade(OpenStreet)中国地图图片是无偏移的。而Google中国地图服务,MapAbc中国地图服务是有偏移,CloudMade地图服务是无偏移的。所以在选择地图类型和地图服务类型时,要么都选择有偏移,要么都选择无偏移。否则地图在显示路径时或地址时就不匹配。
下面列表是合法的组合:
地图类型 (MapType) 地图服务类型 (DigitalMapService)
GOOGLECHINA GOOGLE_MAP_SERVICE
MICROSOFTCHINA GOOGLE_MAP_SERVICE
MAPABCCHINA GOOGLE_MAP_SERVICE
OPENSTREETMAP CLOUDMADE_MAP_SERVICE
GOOGLECHINA MAPABC_MAP_SERVICE
MICROSOFTCHINA MAPABC_MAP_SERVICE
MAPABCCHINA MAPABC_MAP_SERVICE
下述示列地图类型使用MICROSOFTCHINA,而使用不同的地图服务时路径查询的情况。(南京到天津的路径)
[java]
package com.pstreets.gisengine.demo;
import com.mapdigit.gis.MapDirection;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.service.DigitalMapService;
import com.mapdigit.gis.service.IRoutingListener;
import com.pstreets.gisengine.R;
import com.pstreets.gisengine.SharedMapInstance;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MapServiceType extends Activity implements IRoutingListener {
@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, 15,
com.mapdigit.gis.raster.MapType.MICROSOFTCHINA);
//SharedMapInstance.map.setCurrentMapService(DigitalMapService.GOOGLE_MAP_SERVICE);
// SharedMapInstance.map.setCurrentMapService(DigitalMapService.MAPABC_MAP_SERVICE);
SharedMapInstance.map.setCurrentMapService(DigitalMapService.CLOUDMADE_MAP_SERVICE);
SharedMapInstance.map.setRoutingListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.maprouting_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.getdirection:
GeoLatLng latLng1 = new GeoLatLng(32.0418381, 118.7788905);
GeoLatLng latLng2 = new GeoLatLng(39.11643, 117.180908);
SharedMapInstance.map.getDirections(new GeoLatLng[] { latLng1,
latLng2 });
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void done(String query, MapDirection result) {
if (result != null) {
SharedMapInstance.map.setMapDirection(result);
//SharedMapInstance.map.resize(result.getBound());
//SharedMapInstance.map.setZoom(5);
SharedMapInstance.map.setZoom(15);
SharedMapInstance.map.panTo(result.routes[0].startGeocode.point);
}
}
@Override
public void readProgress(int bytes, int total) {
}
}
package com.pstreets.gisengine.demo;
import com.mapdigit.gis.MapDirection;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.service.DigitalMapService;
import com.mapdigit.gis.service.IRoutingListener;
import com.pstreets.gisengine.R;
import com.pstreets.gisengine.SharedMapInstance;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MapServiceType extends Activity implements IRoutingListener {
@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, 15,
com.mapdigit.gis.raster.MapType.MICROSOFTCHINA);
//SharedMapInstance.map.setCurrentMapService(DigitalMapService.GOOGLE_MAP_SERVICE);
// SharedMapInstance.map.setCurrentMapService(DigitalMapService.MAPABC_MAP_SERVICE);
SharedMapInstance.map.setCurrentMapService(DigitalMapService.CLOUDMADE_MAP_SERVICE);
SharedMapInstance.map.setRoutingListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.maprouting_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.getdirection:
GeoLatLng latLng1 = new GeoLatLng(32.0418381, 118.7788905);
GeoLatLng latLng2 = new GeoLatLng(39.11643, 117.180908);
SharedMapInstance.map.getDirections(new GeoLatLng[] { latLng1,
latLng2 });
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void done(String query, MapDirection result) {
if (result != null) {
SharedMapInstance.map.setMapDirection(result);
//SharedMapInstance.map.resize(result.getBound());
//SharedMapInstance.map.setZoom(5);
SharedMapInstance.map.setZoom(15);
SharedMapInstance.map.panTo(result.routes[0].startGeocode.point);
}
}
@Override
public void readProgress(int bytes, int total) {
}
}
补充:移动开发 , Android ,