【问题标题】:How Can I find Nearest City by lat, lng using Google MAP API如何使用 Google MAP API 通过 lat、lng 找到最近的城市
【发布时间】:2017-09-15 12:52:32
【问题描述】:

我正在尝试使用 Google Map API 获取城市名称,但没有得到。 我已经使用 Google API 获得了 Lat, Lng 现在我想获得 10KM 距离内的城市名称。

我正在使用以下 URL 获取 LatLnghttps://maps.googleapis.com/maps/api/geocode/json?address=Coburg,Austrelia&key=""

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=".$lat.",".$long."&radius=10000&type=administrative_area_level_2&key=""

【问题讨论】:

    标签: php google-maps google-maps-api-3 geo


    【解决方案1】:
    You can try this
    ProgressDialog dialog=null;
       @Override
        public void onClick(View v) {
                dialog = ProgressDialog.show(context, "", "Please! Wait...", true);
                GetCurrentAddress result = new GetCurrentAddress();
                result.execute("");
            }
    
    
    
        // getting address task
        private class GetCurrentAddress extends AsyncTask<String, Void, String> {
    
            @Override
            protected String doInBackground(String... urls) {
                String responseText = null;
                String googleurl = "http://maps.google.com/maps/geo?";
                String latitude="38.89";
                String longitude ="-77.03";
          StringBuilder sbuilder=new StringBuilder();
          sbuilder.append(googleurl);
    
          sbuilder.append("q="+latitude+","+longitude);
          sbuilder.append("&amp;output=responseText&amp;sensor=true");
          String url=sbuilder.toString();
    
          try { 
              DefaultHttpClient httpclient=new DefaultHttpClient(); 
              HttpPost httppost=new HttpPost(url); 
              HttpResponse httpresponse=httpclient.execute(httppost); 
              HttpEntity httpentity=httpresponse.getEntity(); 
              InputStream is=httpentity.getContent();
              BufferedReader reader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
              StringBuilder sb=new StringBuilder();
              String line=null;
            while((line=reader.readLine())!=null)
             { 
              sb.append(line+"\n");
    
             } 
            is.close(); 
            responseText=sb.toString();
          } 
          catch(ClientProtocolException e) 
          { 
              e.printStackTrace(); 
          } 
          catch (IOException e) 
          { 
              e.printStackTrace();
          }
          return responseText;
          }
    
            @Override
            protected void onPostExecute(String resultString) {
                dialog.dismiss();
    
                String response= resultString;
    
                if (responseText != null) {
                    Log.v(TAG, "json response is:" + response);
                    try {
                        jObj = new JSONObject(response);
                        jsonarray = jObj.getJSONArray("Placemark");
                        for (int i = 0; i < jsonarray.length(); i++) {
                            JSONObject innerJsonobject = jsonarray.getJSONObject(i);
                            String jsonaddress = innerJsonobject
                                    .getString("address");
    
    
                        }
    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-11
      • 2019-04-21
      • 2012-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      相关资源
      最近更新 更多