Android 当使用GooglePlacesAPI滚动地图时,如何更新附近的位置?
我正在尝试使用GooglePlacesAPI创建一个自定义地点选择器。在Google Place Picker控件中,当地图滚动时,pin位置将发生变化,并获取新pin位置对应的附近位置。 在iOS/Android Google Places API中,我只看到从设备当前位置获取附近位置的API Google Places WebService API可用于获取任何给定lat/long的附近位置,但是否可以通过iOS/Android API实现 如何使用iOS/Android Google places API获取地图滚动到的特定坐标的附近位置?您应该使用来选择自定义位置 以下代码将启动位置选择器Android 当使用GooglePlacesAPI滚动地图时,如何更新附近的位置?,android,ios,google-maps,google-places-api,google-places,Android,Ios,Google Maps,Google Places Api,Google Places,我正在尝试使用GooglePlacesAPI创建一个自定义地点选择器。在Google Place Picker控件中,当地图滚动时,pin位置将发生变化,并获取新pin位置对应的附近位置。 在iOS/Android Google Places API中,我只看到从设备当前位置获取附近位置的API Google Places WebService API可用于获取任何给定lat/long的附近位置,但是否可以通过iOS/Android API实现 如何使用iOS/Android Google pl
int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
您应该使用来选择自定义位置
以下代码将启动位置选择器
int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
在附近的地方使用此张贴方法 以米为单位设置半径
String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json" + "?location=" + location.getLatitude() + "," + location.getLongitude() + "&radius=" + RADIUS_IN_METERS + "&type=" + SEARCH_TYPE + "&key=" + API_KEY;
Log.d(TAG, url);
Map<String, String> params = new HashMap<>();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
locationList = new ArrayList<>();
JSONArray results = response.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject geometry = results.getJSONObject(i).getJSONObject("geometry");
String name = results.getJSONObject(i).getString("name");
String address = results.getJSONObject(i).getString("vicinity");
String place_id = results.getJSONObject(i).getString("place_id");
if (geometry != null) {
JSONObject location = geometry.getJSONObject("location");
if (location != null) {
double latitude = location.getDouble("lat");
double longitude = location.getDouble("lng");
if (latitude != 0.0 && longitude != 0.0) {
Location markerLocation = new Location(SEARCH_TYPE);
markerLocation.setLatitude(latitude);
markerLocation.setLongitude(longitude);
Bundle bundle = new Bundle();
bundle.putString("NAME", name);
bundle.putString("ADDRESS", address);
bundle.putString("PLACE_ID", place_id);
bundle.putString("TYPE", SEARCH_TYPE);
markerLocation.setExtras(bundle);
locationList.add(markerLocation);
Log.d(TAG, latitude + " " + longitude);
}
}
}
}
if (locationList.size() != 0) {
addMarkers(SEARCH_TYPE);
}
//Log.d(TAG,results.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
requestQueue.add(jsonObjectRequest);
stringurl=”https://maps.googleapis.com/maps/api/place/nearbysearch/json“+”?location=“+location.getLatitude()+”、“+location.getLatitude()+”&radius=“+radius\u IN_METERS+”&type=“+SEARCH\u type+”&key=“+API\u key;
Log.d(标签、url);
Map params=新的HashMap();
JsonObjectRequest JsonObjectRequest=新JsonObjectRequest(Request.Method.POST、url、新JSONObject(params),
新建响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
locationList=新的ArrayList();
JSONArray results=response.getJSONArray(“结果”);
对于(int i=0;i
在附近的地方使用此张贴方法
以米为单位设置半径
String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json" + "?location=" + location.getLatitude() + "," + location.getLongitude() + "&radius=" + RADIUS_IN_METERS + "&type=" + SEARCH_TYPE + "&key=" + API_KEY;
Log.d(TAG, url);
Map<String, String> params = new HashMap<>();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
locationList = new ArrayList<>();
JSONArray results = response.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject geometry = results.getJSONObject(i).getJSONObject("geometry");
String name = results.getJSONObject(i).getString("name");
String address = results.getJSONObject(i).getString("vicinity");
String place_id = results.getJSONObject(i).getString("place_id");
if (geometry != null) {
JSONObject location = geometry.getJSONObject("location");
if (location != null) {
double latitude = location.getDouble("lat");
double longitude = location.getDouble("lng");
if (latitude != 0.0 && longitude != 0.0) {
Location markerLocation = new Location(SEARCH_TYPE);
markerLocation.setLatitude(latitude);
markerLocation.setLongitude(longitude);
Bundle bundle = new Bundle();
bundle.putString("NAME", name);
bundle.putString("ADDRESS", address);
bundle.putString("PLACE_ID", place_id);
bundle.putString("TYPE", SEARCH_TYPE);
markerLocation.setExtras(bundle);
locationList.add(markerLocation);
Log.d(TAG, latitude + " " + longitude);
}
}
}
}
if (locationList.size() != 0) {
addMarkers(SEARCH_TYPE);
}
//Log.d(TAG,results.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
requestQueue.add(jsonObjectRequest);
stringurl=”https://maps.googleapis.com/maps/api/place/nearbysearch/json“+”?location=“+location.getLatitude()+”、“+location.getLatitude()+”&radius=“+radius\u IN_METERS+”&type=“+SEARCH\u type+”&key=“+API\u key;
Log.d(标签、url);
Map params=新的HashMap();
JsonObjectRequest JsonObjectRequest=新JsonObjectRequest(Request.Method.POST、url、新JSONObject(params),
新建响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
locationList=新的ArrayList();
JSONArray results=response.getJSONArray(“结果”);
对于(int i=0;i