Android Open Source - CommonLibs Baidu Map Utils






From Project

Back to project page CommonLibs.

License

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.

Java Source Code

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??
     *-------------------------*/

}




Java Source Code List

com.alex.common.AppConfig.java
com.alex.common.AppControl.java
com.alex.common.Err.java
com.alex.common.OnHttpRequestReturnListener.java
com.alex.common.activities.BaseActivity.java
com.alex.common.activities.ImageLoadActivity.java
com.alex.common.activities.WebViewActivity.java
com.alex.common.apis.HttpApi.java
com.alex.common.exception.RetErrorException.java
com.alex.common.utils.BackgroundHandler.java
com.alex.common.utils.BaiduMapUtils.java
com.alex.common.utils.DateTimeUtils.java
com.alex.common.utils.DeviceUtils.java
com.alex.common.utils.DialogUtils.java
com.alex.common.utils.FileUtils.java
com.alex.common.utils.ImageUtils.java
com.alex.common.utils.KLog.java
com.alex.common.utils.Misc.java
com.alex.common.utils.NetworkUtils.java
com.alex.common.utils.PrefUtils.java
com.alex.common.utils.ShareUtils.java
com.alex.common.utils.StringUtils.java
com.alex.common.utils.ThreadUtils.java
com.alex.common.utils.ToastUtils.java
com.alex.common.views.ZoomImageView.java