Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google places API return a single type "car_repair"

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 enter image description here

like image 759
Craig Gallagher Avatar asked Mar 17 '16 12:03

Craig Gallagher


People also ask

What is place type?

Place Types are data-driven ways to define and visualize the many aspects of land use-transportation interactions embodied in our land use plans. They are then used as an input to the Regional Strategic Planning Model (RSPM), allowing us to measure the impact of future changes to transportation and land use policies.

How can I get a free Google Places API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.

What is ADMINISTRATIVE_AREA_LEVEL_1?

ADMINISTRATIVE_AREA_LEVEL_1 indicates a first-order civil entity below the country level. ADMINISTRATIVE_AREA_LEVEL_2. ADMINISTRATIVE_AREA_LEVEL_2 indicates a second-order civil entity below the country level.

Is Google places an API?

The Places API is a service that returns information about places using HTTP requests. Places are defined within this API as establishments, geographic locations, or prominent points of interest.


1 Answers

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
like image 56
jonhid Avatar answered Sep 18 '22 14:09

jonhid