Android Map和Location開發

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調用受限。
      使用場景:獲取用戶選擇具體位置時,獲取經緯度信息。

  • 不能根據關鍵字來獲取位置推薦信息

    • findAutocompletePredictionsfetchPlace(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;
    }

註冊google後臺
Map sdk
Place sdk
Geocoding api

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章