【问题标题】:Finding places of interest within a circle在圆圈内寻找感兴趣的地方
【发布时间】:2016-05-19 01:02:14
【问题描述】:

我正计划构建一个 android 应用程序,该应用程序在地图上的某个点周围画一个圆圈,并找到该圆圈内的所有兴趣点(例如酒店)。

我通过使用 Google Maps Android API 在我的应用中创建了圈子

 GoogleMap map;
 Circle circle = map.addCircle(new CircleOptions()
 .center(new LatLng(MY_LAT, MY_LONG))
 .radius(MY_RADIUS)
 .strokeColor(Color.RED)
 .fillColor(Color.BLUE));

我还知道我可以使用 Google Places API 找到感兴趣的地方。

据我所知,PlacePicker 用于搜索感兴趣的地方。

经过进一步研究,我意识到我实际上可以使用LatLngBoundssetLatLngBounds() 方法为PlacePicker 设置LatLng 边界。该方法接受东北角和西南角,但我如何确定它们?

我的问题是 - 如何让 PlacePicker 扫描给定圈子内的所有兴趣地点?

我想到的一种可能的解决方法是:

1) 使用this method获取一组NE和SW点

2) 将这些作为参数添加到setLatLngBounds() 方法

3) 使用 PlacePicker

这是合适的方式吗?还是有更短的解决方法?

【问题讨论】:

  • 欢迎回来!对于 PlacePicker,请参阅我的问题 here,对于查找该圈内的所有兴趣点,请参阅 this

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


【解决方案1】:

你可能不得不使用

StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
                googlePlacesUrl.append("location=" + latLng.latitude + "," + latLng.longitude);
                googlePlacesUrl.append("&radius=" + 3);
                googlePlacesUrl.append("&types=" + type);
                googlePlacesUrl.append("&sensor=true");
                googlePlacesUrl.append("&key=" + "server key from google console");

只需使用类型作为酒店等,半径可能取决于您的需要。

【讨论】:

  • 谢谢!我将尝试实施它并通知您更新! :)
猜你喜欢
  • 2016-04-27
  • 2011-01-21
  • 2013-07-06
  • 2016-08-31
  • 1970-01-01
  • 2011-08-10
  • 1970-01-01
  • 2022-01-13
相关资源
最近更新 更多