[英]How to remove unrequired places from google places API?
I've created a google places API for my app, it currently shows all the places nearby like hospitals, restaurants, schools etc. I want it to show only restaurants. 我已经为我的应用程序创建了一个Google Places API,它目前显示附近的所有地方,例如医院,餐馆,学校等。我希望它仅显示餐馆。 Is it possible?
可能吗? If so, how?
如果是这样,怎么办? Help would be much appreciated.
帮助将不胜感激。 Thanks :)
谢谢 :)
MapActivity.JAVA MapActivity.JAVA
package com.golo.acer.mrestro4;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
public class MapActivity extends AppCompatActivity {
private static final int PLACE_PICKER_REQUEST = 1;
private TextView mName;
private TextView mAddress;
private TextView mAttributions;
private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW = new LatLngBounds(
new LatLng(27.689753, 85.311188), new LatLng(27.689753, 85.311188));
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place_picker);
mName = (TextView) findViewById(R.id.textView);
mAddress = (TextView) findViewById(R.id.textView2);
mAttributions = (TextView) findViewById(R.id.textView3);
Button pickerButton = (Button) findViewById(R.id.pickerButton);
pickerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
PlacePicker.IntentBuilder intentBuilder =
new PlacePicker.IntentBuilder();
intentBuilder.setLatLngBounds(BOUNDS_MOUNTAIN_VIEW);
Intent intent = intentBuilder.build(MapActivity.this);
startActivityForResult(intent, PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException
| GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
public void moveToInternalChoiceActivity(View view) {
Intent intent = new Intent(this, InternalChoiceActivity.class);
startActivity(intent);
}
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST
&& resultCode == Activity.RESULT_OK) {
final Place place = PlacePicker.getPlace(this, data);
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
String attributions = (String) place.getAttributions();
if (attributions == null) {
attributions = "";
}
mName.setText(name);
mAddress.setText(address);
mAttributions.setText(Html.fromHtml(attributions));
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
place.getPlaceTypes()
returns a list of integer, check if it contains Place.TYPE_RESTAURANT
if finding the restaurant type is your intention. place.getPlaceTypes()
返回一个整数列表,如果您打算查找餐厅类型,请检查它是否包含Place.TYPE_RESTAURANT
。 You can get the type values in the Place
class, beginning with TYPE_
. 您可以在
Place
类中以TYPE_
开头的类型值。
Ref https://developers.google.com/android/reference/com/google/android/gms/location/places/Place 引用https://developers.google.com/android/reference/com/google/android/gms/location/places/Place
[Edit] In your code : [编辑]在您的代码中:
final Place place = PlacePicker.getPlace(this, data);
List<Integer> types = place.getPlaceTypes();
for(Integer i : types){
if (i == Place.TYPE_RESTAURANT){
// its restaurant do something
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
String attributions = (String) place.getAttributions();
if (attributions == null) {
attributions = "";
}
mName.setText(name);
mAddress.setText(address);
mAttributions.setText(Html.fromHtml(attributions));
}
}
[Edit : (comments from user)] [编辑:(来自用户的评论)]
What you are describing as red icon is a marker, you can add them on the map. 您所描述的红色图标是一个标记,您可以在地图上添加它们。 so in your
onActivityResult
you get a Place
(already shown in your code). 因此,在
onActivityResult
您将获得一个Place
(已在代码中显示)。 Place contains name and position, using that show a marker on the map like this: 地点包含名称和位置,使用该名称和位置可以在地图上显示标记,如下所示:
Marker markerPlace = map.addMarker(new MarkerOptions().position(place.getLatLng()).title(place.getName));
Check the documentation and related articles for map marker. 检查文档和相关文章以了解地图标记。
Now how to add a Map ?? 现在如何添加地图? dont ask me, check for information in the internet http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html#mapsview
不要问我,请在互联网上查看信息http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html#mapsview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.