【问题标题】:List of close places without using a map object on android在 android 上不使用地图对象的关闭地点列表
【发布时间】:2017-01-22 18:31:08
【问题描述】:

我正在制作一个需要检查用户是否靠近感兴趣的地方的 Android 应用程序,例如电影院。 (1公里以内)

但是,我不需要用户查看我认为使用 google places api 所需的地图。我已经做了一些研究,但不确定如何在 android 上完成这项工作。任何提示(包括 cmets 或相关链接将不胜感激)

【问题讨论】:

标签: android google-maps google-places-api


【解决方案1】:

查看附近的站点,

1.- 使用来自谷歌地图的Nearby Search Requestslink here

2.- 使用手机坐标,获取坐标附近的电影院列表...

https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.503186,-0.126446&radius=5000&types=movie+theater&key=YOUR_API_KEY

3.- 比较两个坐标,然后施展你的魔法,也许可以通过这两个点获得距离并向用户显示距离..

注意:如果你想要很多特别的地方,你需要去看看 另一种方法。这就是我的想法......是,在你的服务器 需要通过许多最近的地方的坐标提出请求, (博物馆,电影院等),并保存,因为谷歌向你收费 当服务器多次签入时,当用户发送 坐标您将获得最近地点的列表,如果没有,请咨询 最好的列表并保存在您的服务器中并发送给用户,

你需要使用一些计算坐标,比如范围,如果用户 靠近我在数据库中发送的这个坐标 如果没有信息,请向服务器请求咨询最近的地方 (与您的预定清单)

对不起,我的英语不好。

更多信息的链接
Find Places Nearby in Google Maps using Google Places API–Android App
Places APIs and Related Products
how to display nearby places like atm,hospitals in android google map?

【讨论】:

  • 这应该很好用。您可以使用 GPS 上的广播接收器获取手机位置,并使用 Volley 投射请求并解析响应。
【解决方案2】:

如果我正确理解了您的问题,您正在寻找 GeoFences。在这里查看更多详细信息:https://developer.android.com/training/location/geofencing.html

【讨论】:

    【解决方案3】:

    试试这个以获取地点,输入您自己的搜索查询

    searchString = getIntent().getStringExtra("search_key");
    GetPlacesTask getPlacesTask = new GetPlacesTask();
    String url = getResources().getString(R.string.near_by_search) +
                "location="+latitude+","+longitude+"&radius=1000&type=" +
                searchString +"&keyword="+ searchString +
                "&key="+ YOUR_API_KEY;
    String[] stringArray = new String[]{url};
    getPlacesTask.execute(stringArray);
    

    GetPlacesTask

    private class GetPlacesTask extends AsyncTask<String, String, ArrayList<Place>>
    {
        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
        }
    
        @Override
        protected ArrayList<Place> doInBackground(String... strings)
        {
            try
            {
                URL url = new URL(strings[0]);
                HttpHandler httpHandler = new HttpHandler(url);
                String result = httpHandler.getURLResponse();
                ArrayList<Place> placesArrayList = new ArrayList<>();
                JSONObject mainResponse;
                JSONArray jsonArray;
                mainResponse = new JSONObject(jsonString);
                jsonArray = mainResponse.getJSONArray("results");
               if(jsonArray.length() > 0)
               {
                   placesArrayList = fetch(jsonArray);
               }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return placesArrayList;
        }
    
        @Override
        protected void onPostExecute(ArrayList<Place> placesArrayList)
        {
            super.onPostExecute(placesArrayList);
    
            if(!placesArrayList.isEmpty())
            {
                //Show Places in your views
            }
        }
    }
    

    HttpHandler 类

     public class HttpHandler
    {
    private URL url;
    public HttpHandler(URL url)
    {
        this.url = url;
    }
    
    public String getURLResponse()
    {
        String response = "";
    
        try
        {
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            InputStream is = new BufferedInputStream(urlConnection.getInputStream());
            response = convertStreamIntoString(is);
            Log.d("RESPONSE", response);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    
    
        return response;
    }
    
    private String convertStreamIntoString(InputStream inputStream)
    {
        String response = "";
        String line;
        try
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder sb = new StringBuilder();
            while ((line = reader.readLine()) != null)
            {
                sb.append(line);
            }
            response = sb.toString();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    
        return response;
    }
    }
    

    Here is the repository for the same

    【讨论】:

      【解决方案4】:

      您还可以在附近的地方使用 Awareness Api。 您只需创建 GoogleApiClient 对象,如下所示 -

      GoogleApiClient  mGoogleApiClient = new GoogleApiClient.Builder(this)
                      .addApi(Awareness.API)
                      .addConnectionCallbacks(this)
                      .build();
      
       mGoogleApiClient.connect();
      

      然后为附近的地方调用下面的方法。

      private void detectNearbyPlaces() {
              if (!checkLocationPermission()) {
                  return;
              }
      
              Awareness.SnapshotApi.getPlaces(mGoogleApiClient)
                      .setResultCallback(new ResultCallback<PlacesResult>() {
                          @Override
                          public void onResult(@NonNull PlacesResult placesResult) {
                              Place place;
                              if (placesResult.getPlaceLikelihoods() != null) {
                                  for (PlaceLikelihood placeLikelihood : placesResult.getPlaceLikelihoods()) {
                                      place = placeLikelihood.getPlace();
                                      Log.e(TAG, place.getName().toString() + "\n" + place.getAddress().toString());
                                      Log.e(TAG, "Rating: " + place.getRating());
                                      Log.e(TAG, "Likelihood that the user is here: " + placeLikelihood.getLikelihood() * 100 + "%");
                                  }
                              }
                          }
                      });
          }
      

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-28
        • 1970-01-01
        • 2021-03-18
        相关资源
        最近更新 更多