This is the first time using google map API and google places API. I am doing a demo application that displays the list hospitals (for example) nearest to the user's location with routes to each of the hospitals. I been able to get the user's location with the code below the:
public class MainActivity extends ActionBarActivity {
private GoogleMap map;
UiSettings mapSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if (map != null) {
// map.addMarker(new MarkerOptions().position(myLocation).title("Start"));
map.setMyLocationEnabled(true);
mapSettings = map.getUiSettings();
mapSettings.setScrollGesturesEnabled(true);
mapSettings.setZoomControlsEnabled(true);
}
}
}
The xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
My question how do I get the list of hospitals using google places API and display them. Any help,tips,walkthrough or tutorials will really be appericaited.Thanks in Advance.
Follow this link, it has all explained out,
in the String type='grocery_or_supermarket' replace it to be 'hospital' and you'll be good to go:
http://androidmastermind.blogspot.co.ke/2016/06/android-google-maps-with-nearyby-places.html
This will load the near by hospital according to your location.
Follow below code:
For Android, I tried to use
Place picker for Android
. It can add thebuilt-in place picker UI widget
to your app, so users can choose from a set of nearby places displayed on a map. It easy to use, you just need to do is:It will show the UI below to pick a place for you, and you can get the place info by using below:
For more details, please refer to guide here and code here.
However, it cannot set the place type because it no feature for the Build in UI.. If you really need to set, you should use
Google Places API Web Service API
here, search the location yourself, parse the JSON data, and show on your own UI.A Nearby Search lets you search for places within a specified area. You can refine your search request by supplying keywords or specifying the type of place you are searching for.
A Nearby Search request is an HTTP URL of the following form:
Note that in parameters you need to set
types=hospital
EDIT
Example on how to pass the search request for specific locations in JSON using the google places API web API web service API.
Request
Url for this:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670,151.1957&radius=500&types=food&name=cruise&key=API_KEY
and Response JSON like this:
The below example returns a list of hospitals near London, England.
For more details please refer here.