Android 系統Geocoder API能力
- getFromLocation(double latitude, double longitude, int maxResults) 可以指定語言(限原生系統)國內一般接的是高德和百度服務 不一定支持多語言。
- getFromLocationName(String locationName, int maxResults)
- getFromLocationName(String locationName, int maxResults,
double lowerLeftLatitude, double lowerLeftLongitude,
double upperRightLatitude, double upperRightLongitude)
Google Map 、 Location、Places Sdk
- 定位
定位快、依賴google服務
-
獲取(經緯度)當前周邊推薦
-
placed sdk:
1). findCurrentPlace: 文檔說明基本信息免費使用,測試發現每次調用需要間隔1-2分鐘。
用場景:用戶點擊入口進入地圖時,獲取附近地理位置以及周邊地址推薦列表2). findAutocompletePredictions:文檔說明基本信息免費使用,測試發現每次調用需要間隔1-2分鐘。
使用場景:用戶輸入關鍵字,獲取相關推薦地址3). fetchPlace:收費,目前demo調用受限。
使用場景:獲取用戶選擇具體位置時,獲取經緯度信息。
-
-
不能根據關鍵字來獲取位置推薦信息
findAutocompletePredictions
和fetchPlace(FetchPlaceResponse)
配合使用,findAutocompletePredictions
可以拿到placeId再通過fetchPlace(FetchPlaceResponse)
獲取到相應的地理位置 (可以指定當前界面的語言,從而可以得到相應語言地址)
Google地圖反解功能
- web api
https://maps.googleapis.com/maps/api/geocode/json
- 需要收費,啓用
Geocoding API
“error_message” : “You have exceeded your daily request quota for this API. If you did not set a custom daily request quota, verify your project has an active billing account: http://g.co/dev/maps-no-account”,
maps-no-account",
“results” : [],
“status” : “OVER_QUERY_LIMIT”
MyTask task = new MyTask(new Runnable() {
@Override
public void run() {
String url = "https://maps.googleapis.com/maps/api/geocode/json" + "?latlng=" + latitude + "," + longitude
+ "&language=" + language + "&key=" + context.getString(R.string.google_maps_key);
RequestQueue requestQueue = Volley.newRequestQueue(context);
Request<String> stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
LOG.i(TAG, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
LOG.i(TAG, error.getMessage());
}
});
requestQueue.add(stringRequest);
}
});
task.execute();
檢測gps可用代碼
public static boolean checkGPSStatus(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (locationManager == null) {
return false;
}
boolean isOpen = false;
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|| locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
isOpen = true;
}
return isOpen;
}