百度地图之短串分享(三)
if (error != 0 || res == null) {
Toast.makeText(ShareDemoActivity.this, "抱歉,未找到结果",
Toast.LENGTH_LONG).show();
return;
}
AddrShareOverlay addrOverlay = new AddrShareOverlay(
getResources().getDrawable(R.drawable.icon_marka),
mMapView, res);
mMapView.getOverlays().clear();
mMapView.getOverlays().add(addrOverlay);
mMapView.refresh();
}
public void onGetBusDetailResult(MKBusLineResult result, int iError) {
}
@Override
public void onGetSuggestionResult(MKSuggestionResult res, int arg1) {
}
@Override
public void onGetShareUrlResult(MKShareUrlResult result, int type,
int error) {
// 分享短串结果
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_TEXT, "您的朋友通过百度地图SDK与您分享一个位置: "
+ currentAddr + " -- " + result.url);
it.setType("text/plain");
startActivity(Intent.createChooser(it, "将短串分享到"));
}
});
}
@Override
protected void onPause() {
mMapView.onPause();
super.onPause();
}
@Override
protected void onResume() {
mMapView.onResume();
super.onResume();
}
@Override
protected void onDestroy() {
mMapView.destroy();
super.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mMapView.onRestoreInstanceState(savedInstanceState);
}
private void initMapView() {
mMapView.setLongClickable(true);
mMapView.getController().setZoom(14);
mMapView.getController().enableClick(true);
mMapView.setBuiltInZoomControls(true);
}
public void sharePoi(View view) {
// 发起poi搜索
mSearch.poiSearchInCity(mCity, searchKey);
Toast.makeText(this, "在" + mCity + "搜索 " + searchKey,
Toast.LENGTH_SHORT).show();
}
public void shareAddr(View view) {
// 发起反地理编码请求
mSearch.reverseGeocode(mPoint);
Toast.makeText(
this,
String.format("搜索位置: %f,%f", (mPoint.getLatitudeE6() * 1E-6),
(mPoint.getLongitudeE6() * 1E-6)), Toast.LENGTH_SHORT)
.show();
}
/**
* 使用PoiOverlay 展示poi点,在poi被点击时发起短串请求.
*
* @author kehongfeng
*
*/
private class PoiShareOverlay extends PoiOverlay {
public PoiShareOverlay(Activity activity, MapView mapView) {
super(activity, mapView);
}
@Override
protected boolean onTap(int i) {
MKPoiInfo info = getPoi(i);
currentAddr = info.address;
mSearch.poiDetailShareURLSearch(info.uid);
re