Java Google Places API获取特定类型“;“汽车修理”;
我正在Android Studio中制作一个应用程序,用户可以在其中找到他们所在区域的所有机制。我正在使用google places来完成这项工作,目前我能够找到我所在地区附近的所有地方,但是我似乎无法将类型过滤为“Car_Repair”。有人能帮我解决这个问题吗 位置选择器活性Java Google Places API获取特定类型“;“汽车修理”;,java,android,android-studio,google-maps-android-api-2,google-places-api,Java,Android,Android Studio,Google Maps Android Api 2,Google Places Api,我正在Android Studio中制作一个应用程序,用户可以在其中找到他们所在区域的所有机制。我正在使用google places来完成这项工作,目前我能够找到我所在地区附近的所有地方,但是我似乎无法将类型过滤为“Car_Repair”。有人能帮我解决这个问题吗 位置选择器活性 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.
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;
import java.util.ArrayList;
import java.util.List;
public class PlacePickerActivity extends AppCompatActivity {
private static final int PLACE_PICKER_REQUEST = 1;
String url="https://maps.googleapis.com/maps/api/place/textsearch/json?type=car_repair&key=AIzaSyB86znUFrlT9mNC8xm00Jc2-AirUU9U_2I";
private TextView mName;
private TextView mAddress;
private TextView mAttributions;
private TextView mNumber;
private TextView car;
private static final LatLngBounds Sligo = new LatLngBounds(
new LatLng(54.27, -8.47), new LatLng(54.27, -8.47));
@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);
mNumber = (TextView) findViewById(R.id.textView4);
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(Sligo);
List<Integer> filterTypes = new ArrayList<Integer>();
filterTypes.add(Place.TYPE_CAR_REPAIR);
Intent intent = intentBuilder.build(PlacePickerActivity.this);
startActivityForResult(intent, PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException
| GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
@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();
final CharSequence formatted_phone_number = place.getPhoneNumber();
// final CharSequence car = place.TYPE_CAR_REPAIR();
//public abstract List<Integer> getTypeFilter(place.TYPE_CAR_REPAIR);
String attributions = (String) place.getAttributions();
if (attributions == null) {
attributions = "";
}
mName.setText(name);
mAddress.setText(address);
mAttributions.setText(Html.fromHtml(attributions));
mNumber.setText(formatted_phone_number);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.support.v7.app.AppActivity;
导入android.text.Html;
导入android.view.view;
导入android.widget.Button;
导入android.widget.TextView;
导入com.google.android.gms.common.GooglePlayServicesNotAvailableException;
导入com.google.android.gms.common.GooglePlayServicesRepairableException;
导入com.google.android.gms.location.places.Place;
导入com.google.android.gms.location.places.ui.PlacePicker;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.LatLngBounds;
导入java.util.ArrayList;
导入java.util.List;
公共类PlacePickerActivity扩展了AppCompatActivity{
私有静态最终整数位置\u选择器\u请求=1;
字符串url=”https://maps.googleapis.com/maps/api/place/textsearch/json?type=car_repair&key=AIzaSyB86znUFrlT9mNC8xm00Jc2-airuu9u2i”;
私有文本视图mName;
私人文本视图;
私有文本视图mAttributions;
私有文本视图mNumber;
私家车;
专用静态最终LatLngBounds Sligo=新LatLngBounds(
新LatLng(54.27,-8.47),新LatLng(54.27,-8.47);
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u place\u picker);
mName=(TextView)findViewById(R.id.TextView);
mAddress=(TextView)findViewById(R.id.textView2);
mAttributions=(TextView)findViewById(R.id.textView3);
mNumber=(TextView)findViewById(R.id.textView4);
按钮选择器按钮=(按钮)findViewById(R.id.pickerButton);
pickerButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
试一试{
PlacePicker.IntentBuilder IntentBuilder=
新的PlacePicker.IntentBuilder();
intentBuilder.setLatLngBounds(Sligo);
List filterTypes=new ArrayList();
filterTypes.add(Place.TYPE\u CAR\u REPAIR);
Intent Intent=intentBuilder.build(PlacePickerActivity.this);
startActivityForResult(意图、地点、选取者请求);
}catch(谷歌游戏服务可修复例外
|谷歌PlayServicesNotAvailableException){
e、 printStackTrace();
}
}
});
}
@凌驾
ActivityResult上受保护的void(int请求代码,
int resultCode,意图数据){
if(requestCode==放置\u选择器\u请求
&&结果代码==活动。结果(确定){
final Place=PlacePicker.getPlace(这个,数据);
final CharSequence name=place.getName();
final CharSequence address=place.getAddress();
final CharSequence格式化的_phone_number=place.getPhoneNumber();
//最终CharSequence car=地点。键入_car_REPAIR();
//公共摘要列表getTypeFilter(place.TYPE\u CAR\u REPAIR);
字符串属性=(字符串)place.getAttributes();
如果(属性==null){
归因=”;
}
mName.setText(名称);
mAddress.setText(地址);
setText(Html.fromHtml(attributes));
mNumber.setText(格式化的电话号码);
}否则{
super.onActivityResult(请求代码、结果代码、数据);
}
}
}
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.truiton.placepicker">
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyB86znUFrlT9mNC8xm00Jc2-AirUU9U_2I"/>
<activity
android:name=".PlacePickerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
可能与上一个问题重复,发布与上一个问题基本相同的问题没有意义。这篇新帖子没有提供新的信息(例如,代码除了细微的差异外是相同的),因此它不太可能比你第一次提问时吸引到更好的结果,并且它使其他真正新的问题更难发现。我很高兴你尝试在前面的问题上增加悬赏,这对你来说似乎是一个更好的策略。