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;
}