Android Studio Baidu Map Development (6) Marker bind event, calculate two point distance

Source: Internet
Author: User
Tags cos

Android Studio Baidu Map Development (6) Marker bind event, calculate two point distance

Email:[email protected]

Development Environment : Win7 64-bit,android Studio, please note that Android Studio, using the Navigation SDK version: 3.1.0.

    • Baidu Map Application (1): Android Studio Baidu Map Development (1) Configure project, show map
    • Baidu Map Application (2):Android Studio Baidu Map Development (2) Map positioning
    • Baidu Map Application (3): Android Studio Baidu Map Development (3) Map navigation
    • Baidu Map Application (4): Android Studio Baidu Map Development (4) touch point, geocoding
    • Baidu Map Application (5):Android Studio Baidu Map Development (5) Query peripheral services (petrol station)

One. Maker binding a point-and-click event

/**         * For Baidu map marker increased click Listener function *        /Baidumap.setonmarkerclicklistener (New Baidumap.onmarkerclicklistener () {            @Override public            boolean Onmarkerclick (Marker Marker) {           //response to click event                return false;            }        });

Two. Calculate the distance between two points according to Baidu map coordinates:

/**     * Calculates the distance between two points     * @param start     * @param end     * @return meters */public    String getdistance (latlng start , Latlng end) {        double lat1 = (math.pi/180) *start.latitude;        Double lat2 = (math.pi/180) *end.latitude;        Double lon1 = (math.pi/180) *start.longitude;        Double lon2 = (math.pi/180) *end.longitude;        Earth radius        Double R = 6371;        Two points away, if you want rice, the result *1000        double d =  Math.acos (Math.sin (LAT1) *math.sin (LAT2) +math.cos (LAT1) *math.cos ( LAT2) *math.cos (lon2-lon1)) *r;        if (d<1)            return (int) d*1000+ "M";        else            return String.Format ("%.2f", D) + "km";    }


Android Studio Baidu Map Development (6) Marker bind event, calculate two point distance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.