Back to project page CommonLibs.
The source code is released under:
Apache License
If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.alex.common.utils; /*from www . jav a2 s .c om*/ import android.app.Activity; import android.content.Intent; import android.net.Uri; /** * ???????? * @author caisenchuan */ public class BaiduMapUtils { /*-------------------------- * ??? *-------------------------*/ private static final String TAG = BaiduMapUtils.class.getSimpleName(); /**???????????*/ public static final String BAIDU_MAP_PKT_NAME = "com.baidu.BaiduMap"; /*-------------------------- * ????? *-------------------------*/ /*-------------------------- * ???????? *-------------------------*/ /*-------------------------- * public?? *-------------------------*/ /** * ????marker?????? */ public static String getMarkerQueryString(double lat, double lon, String title, String address, String src) { String url = String.format("marker?location=%s,%s&title=%s&content=%s&src=%s&coord_type=gcj02", lat, lon, title, address, src); return url; } /** * ????????marker?????? */ public static String getMarkerHtmlString(double lat, double lon, String title, String address, String src) { String query = getMarkerQueryString(lat, lon, title, address, src); String ret = String.format("http://api.map.baidu.com/%s&output=html", query); KLog.d(TAG, ret); return ret; } /** * ?????????marker?????? */ public static String getMarkerIntentString(double lat, double lon, String title, String address, String src) { String query = getMarkerQueryString(lat, lon, title, address, src); String ret = String.format("bdapp://map/%s", query); KLog.d(TAG, ret); return ret; } /** * ??????????????marker */ public static void startBaiduMapApp(Activity activity, double lat, double lon, String title, String address, String src) { Uri uri = Uri.parse(getMarkerIntentString(lat, lon, title, address, src)); Intent it = new Intent(Intent.ACTION_VIEW, uri); it.setPackage(BAIDU_MAP_PKT_NAME); activity.startActivity(it); } /** * ??????????????marker */ public static void gotoBaiduMapHtml(Activity activity, double lat, double lon, String title, String address, String src) { Uri uri = Uri.parse(getMarkerHtmlString(lat, lon, title, address, src)); Intent it = new Intent(Intent.ACTION_VIEW, uri); activity.startActivity(it); } /** * ????????????marker??????? -> ?? */ public static void openBaiduMap(Activity activity, double lat, double lon, String title, String address, String src) { if(Misc.isAppInstalled(activity, BAIDU_MAP_PKT_NAME)) { startBaiduMapApp(activity, lat, lon, title, address, src); } else { gotoBaiduMapHtml(activity, lat, lon, title, address, src); } } /*-------------------------- * protected??packet?? *-------------------------*/ /*-------------------------- * private?? *-------------------------*/ }