百度地图学习

获取详细信息:


1 package com.zzw.baidumap;
 2 
 3 import com.baidu.location.BDLocation;
 4 import com.baidu.location.BDLocationListener;
 5 import com.baidu.location.LocationClient;
 6 import com.baidu.location.LocationClientOption;
 7 
 8 import android.app.Activity;
 9 import android.os.Bundle;
10 import android.util.Log;
11 
12 public class MainActivity extends Activity {
13     LocationClient mLocationClient;
14 
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18 //        setContentView(R.layout.activity_main);
19 
20         // 得到LocationClient
21         mLocationClient = new LocationClient(this);
22 
23         // 得到LocationListenner
24         MyLocationListenner mListenner = new MyLocationListenner();
25 
26         // 设置LocationClient选项
27         LocationClientOption option = new LocationClientOption();
28         option.setIsNeedAddress(true);
29         option.setAddrType("all");
30         option.setCoorType("bd09ll");// 设置为百度的定位类型
31 
32         mLocationClient.setLocOption(option);
33 
34         // 注册LocationListener
35         mLocationClient.registerLocationListener(mListenner);
36 
37         // 开始启动
38         mLocationClient.start();
39     }
40 
41     @Override
42     protected void onDestroy() {
43         // 结束启动
44         mLocationClient.stop();
45         super.onDestroy();
46     }
47 
48     // 具体操作
49     private class MyLocationListenner implements BDLocationListener {
50 
51         @Override
52         public void onReceiveLocation(BDLocation location) {
53             try {
54                 // 当前设备位置所在的省
55                 String province = location.getProvince();
56                 Log.d("province", province);
57 
58                 // 当前设备位置所在的市:比如:成都市
59                 String city = location.getCity();
60                 Log.d("city", city);
61 
62                 // 具体地址:从国家到街号-->中国xx省xx市xx区xx路xx号-附x
63                 String addeStr = location.getAddrStr();
64                 Log.d("addeStr", addeStr);
65 
66                 // 国家
67                 String country = location.getCountry();
68                 Log.d("country", country);
69 
70                 // 区,比如:金牛区
71                 String district = location.getDistrict();
72                 Log.d("district", district);
73 
74                 // 街道 比如:西安南路
75                 String street = location.getStreet();
76                 Log.d("street", street);
77 
78                 // 具体的街道号数 比如:60号-附2
79                 String streetNumber = location.getStreetNumber();
80                 Log.d("streetNumber", streetNumber);
81 
82                 // 当前时间
83                 String time = location.getTime();
84                 Log.d("time", time);
85 
86                 Log.d("当前位置", addeStr);
87             } catch (Exception e) {
88                 e.printStackTrace();
89             }
90 
91         }
92 
93     }
94 }

2计算两点距离

DistanceUtil.getDistance(arg0, arg1);

3.某点是否在某点五公里范围内(有现成的方法吗)

你可能感兴趣的:(百度地图学习)