Android高德之旅(18)短串分享
2017-11-15 本文已影响68人
大公爵
废话
短串分享看似不起眼,实则很常用,我们经常分享位置给小伙伴用的就是短串分享。我们分享一个位置给小伙伴不可能把经纬度发过去,一来不直观,二来可能写的很长,三来显得太low,四来直接明文经纬度在有些场景下可能会有问题。所以高德把一个位置转换成几个字符表示的短串,既方便分享,又可以在多平台通用,实在很棒。
简介
短串分享分为四种:
- 位置分享
- 路径分享
- POI分享
- 导航分享
(1)位置分享
public void locationShare() {
ShareSearch shareSearch = new ShareSearch(this.getApplicationContext());
shareSearch.setOnShareSearchListener(this);
LatLonSharePoint point = new LatLonSharePoint(POI_POINT.getLatitude(),
POI_POINT.getLongitude(), "方恒国际中心A座");
shareSearch.searchLocationShareUrlAsyn(point);
}
回调接口是ShareSearch.OnShareSearchListener
shareSearch.setOnShareSearchListener(new ShareSearch.OnShareSearchListener() {
@Override
public void onPoiShareUrlSearched(String url, int errorCode) {
}
@Override
public void onLocationShareUrlSearched(String url, int errorCode) {
}
@Override
public void onNaviShareUrlSearched(String url, int errorCode) {
}
@Override
public void onBusRouteShareUrlSearched(String url, int errorCode) {
}
@Override
public void onWalkRouteShareUrlSearched(String url, int errorCode) {
}
@Override
public void onDrivingRouteShareUrlSearched(String url, int errorCode) {
}
});
我们打印下回调结果
http://f.amap.com/4cpb_07AMnu
http://f.amap.com/4cpb_07AMnu就是最终要的短串,我们可以把这个短串发给别人,别人可以在手机app里打开,也可以在浏览器里打开。
(2)路径分享
public void locationShare() {
ShareSearch shareSearch = new ShareSearch(this.getApplicationContext());
shareSearch.setOnShareSearchListener(this);
ShareSearch.ShareFromAndTo fromAndTo = new ShareSearch.ShareFromAndTo(START, END);
ShareSearch.ShareDrivingRouteQuery query = new ShareSearch.ShareDrivingRouteQuery(fromAndTo,
ShareSearch.DrivingDefault);
shareSearch.searchDrivingRouteShareUrlAsyn(query);
}
返回结果
http://f.amap.com/4cpb_0BDMcE
(3)POI分享
public void locationShare() {
ShareSearch shareSearch = new ShareSearch(this.getApplicationContext());
shareSearch.setOnShareSearchListener(this);
PoiItem item = new PoiItem(null, POI_POINT, "高德软件有限公司", "");
shareSearch.searchPoiShareUrlAsyn(item);
}
返回结果
http://f.amap.com/6aPJO_05E3Mc1
(4)导航分享
public void locationShare() {
ShareSearch shareSearch = new ShareSearch(this.getApplicationContext());
shareSearch.setOnShareSearchListener(this);
ShareSearch.ShareFromAndTo fromAndTo = new ShareSearch.ShareFromAndTo(START, END);
ShareSearch.ShareNaviQuery query = new ShareSearch.ShareNaviQuery(fromAndTo,
ShareSearch.NaviDefault);
shareSearch.searchNaviShareUrlAsyn(query);
}
返回结果
http://f.amap.com/4cpb_057NFq
总结
细不细灰常方便!好吧,短串分享就讲这么多吧,本期节目就到这里,感谢大家收看,我们下期再见~