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