这是“我的代码”示例,该示例对“学校,餐馆”有效,但不适用于加油站。.我认为空间不足。
case R.id.B_restaurant:
mMap.clear();
dataTransfer = new Object[2];
String restaurant = "restaurant";
url = getUrl(latitude, longitude, restaurant);
getNearbyPlacesData = new com.example.husnainbutt.driveescuev22.**GetNearbyPlacesData();**
dataTransfer[0] = mMap;
dataTransfer[1] = url;
getNearbyPlacesData.execute(dataTransfer);
Toast.makeText(MapsActivity.this, "Showing Nearby Restaurants", Toast.LENGTH_LONG).show();
break;
GetNearbyplaces如下所示,看起来不错,但我无法弄清楚包含空格的关键字问题,请帮助我,这样可以节省时间.. !!
public class GetNearbyPlacesData extends AsyncTask<Object, String, String> {
String googlePlacesData;
GoogleMap mMap;
String url;
@Override
protected String doInBackground(Object... objects) {
mMap = (GoogleMap)objects[0];
url = (String)objects[1];
com.example.husnainbutt.driveescuev22.DownloadURL downloadUrl = new com.example.husnainbutt.driveescuev22.DownloadURL();
try {
googlePlacesData = downloadUrl.readUrl(url);
} catch (IOException e) {
e.printStackTrace();
}
return googlePlacesData;
}
@Override
protected void onPostExecute(String s) {
List<HashMap<String, String>> nearbyPlaceList = null;
com.example.husnainbutt.driveescuev22.DataParser parser = new com.example.husnainbutt.driveescuev22.DataParser();
nearbyPlaceList = parser.parse(s);
showNearbyPlaces(nearbyPlaceList);
}
private void showNearbyPlaces(List<HashMap<String,String>> nearbyPlaceList)
{
for(int i = 0;i<nearbyPlaceList.size() ; i++)
{
MarkerOptions markerOptions = new MarkerOptions();
HashMap<String , String> googlePlace = nearbyPlaceList.get(i);
Log.d("onPostExecute","Entered into showing locations");
String placeName = googlePlace.get("place_name");
String vicinity = googlePlace.get("vicinity");
double lat = Double.parseDouble( googlePlace.get("lat") );
double lng = Double.parseDouble( googlePlace.get("lng"));
LatLng latLng = new LatLng(lat, lng);
markerOptions.position(latLng);
markerOptions.title(placeName +" : "+ vicinity);
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
}
}
}
答案 0 :(得分:0)
您可以使用Place
-类型:
https://developers.google.com/places/supported_types?hl=de
使用“ gas_station”类型应该会有所帮助。