谷歌Places API所返回单一类型" car_repair" [英] Google places API return a single type "car_repair"
问题描述
我使用谷歌的地方API和它返回所有的地方在我的位置。不过,我只希望它返回一个类型为汽车修理我觉得我几乎有它,但我失去了一些东西,如果有人能指导我在正确的方向将是巨大的:)
我的code到目前为止
PlacPickerActivity
进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.support.v7.app.AppCompatActivity;
进口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;
公共类PlacePickerActivity扩展AppCompatActivity { 私有静态最终诠释PLACE_PICKER_REQUEST = 1;
串url=\"https://maps.googleapis.com/maps/api/place/textsearch/json?type=car_repair&key=AIzaSyBKsTtLyMBQH8mhvbknJ4MvZwACotmeYO0\"; 私人TextView的MNAME;
私人TextView的mAddress;
私人TextView的mAttributions;
私人TextView的mNumber;
私有静态最后的LatLngBounds斯莱戈=新的LatLngBounds(
新的经纬度(54.27,-8.47),新的经纬度(54.27,-8.47)); @覆盖
保护无效的onCreate(捆绑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);
按钮pickerButton =(按钮)findViewById(R.id.pickerButton);
pickerButton.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
尝试{
PlacePicker.IntentBuilder intentBuilder =
新PlacePicker.IntentBuilder();
intentBuilder.setLatLngBounds(斯莱戈); 意向意图= intentBuilder.build(PlacePickerActivity.this);
startActivityForResult(意向,PLACE_PICKER_REQUEST); }赶上(GooglePlayServicesRepairableException
| GooglePlayServicesNotAvailableException五){
e.printStackTrace();
}
}
});
} @覆盖
保护无效的onActivityResult(INT申请code,
INT结果code,意图数据){ 如果(要求code == PLACE_PICKER_REQUEST
&功放;&安培;结果code == Activity.RESULT_OK){ 最终将地方= PlacePicker.getPlace(这个数据);
最后CharSequence的名称= place.getName();
最终的CharSequence地址= place.getAddress();
最终的CharSequence FORMATTED_PHONE_NUMBER = place.getPhoneNumber();
字符串归因=(字符串)place.getAttributions();
如果(归属== NULL){
归因=;
} mName.setText(名);
mAddress.setText(地址);
mAttributions.setText(Html.fromHtml(归属));
mNumber.setText(FORMATTED_PHONE_NUMBER);
}其他{
super.onActivityResult(要求code,结果code,数据);
}
}}
清单文件
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.truiton.placepicker> <使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/> <应用
机器人:allowBackup =真
机器人:图标=@的mipmap / ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme> &所述;元数据
机器人:名字=com.google.android.gms.version
机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/> &所述;元数据
机器人:名字=com.google.android.geo.API_KEY
机器人:值=AIzaSyBKsTtLyMBQH8mhvbknJ4MvZwACotmeYO0/> <活动
机器人:名字=。PlacePickerActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>< /清单>
当我在网址栏中输入了我的我的电脑上浏览器,它返回所有类型为car_repair在我的领域,所以我的API密钥不工作
尝试用类似这样的查询:
位置是在格式纬度,经度...并小心是类型不会打字。
I'm using Google places API and it is returning all the places in my location. However I only want it to return a type for "car-repair" I think I nearly have it but I'm missing something if anyone could guide me in the right direction it would be great :)
My Code so far PlacPickerActivity
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 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=AIzaSyBKsTtLyMBQH8mhvbknJ4MvZwACotmeYO0";
private TextView mName;
private TextView mAddress;
private TextView mAttributions;
private TextView mNumber;
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);
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();
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);
}
}
}
Manifest File
<?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="AIzaSyBKsTtLyMBQH8mhvbknJ4MvZwACotmeYO0"/>
<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>
When I type in the URL into my browser on my PC it returns all the type "car_repair" in my area therefore my API Key does work
Try with a query similar to this: Location is in format latitude,longitude...and be careful is "types" not type.
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=54.27,-8.47&radius=1000&types=car_repair&key=AddYourOwnKeyHere
这篇关于谷歌Places API所返回单一类型&QUOT; car_repair&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!