Showing nearby places using Google Places API and Google Map Android API V2

February 26, 2013
By

In this article we will develop an Android Application which displays a set of nearby places of current location in Google Map according  to the type entered in the Spinner widget.



This application makes use of Google services like Google Map Android API V2 and Google Places API.

This application is developed in Eclipse (4.2.1) with ADT plugin (21.0.0) and Android SDK (21.0.0) and tested in a real device with Android 2.3.6  ( GingerBread ).



1. Create a new Android application project namely “LocationNearby”

Create a new Android application project

Figure 1 : Create a new Android application project


2. Configure the project

Configure the application project

Figure 2 : Configure the application project


3. Design application launcher icon

Design application launcher icon

Figure 3 : Design application launcher icon


4. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity


5. Enter MainActivity details

Enter MainActivity details

Figure 5 : Enter MainActivity details


6. Download and configure Google Play Services Library in Eclipse

Please follow the given below link to setup Google Play Service library in Eclipse.

http://developer.android.com/google/play-services/setup.html


7. Add Google Play Services Library to this project

Add Google Play Services Library to this project

Figure 6 : Add Google Play Services Library to this project


8. Get the API key for Google Maps Android API V2

We need to get an API key from Google to use Google Maps in Android application.

Please follow the given below link to get the API key for Google Maps Android API v2.

https://developers.google.com/maps/documentation/android/start


9. Get the API key for Google Places API

We can create API key for Google Place API by clicking “Create new Browser key”  available at the “API Access” pane of the Google console URL : http://code.google.com/apis/console.

Also ensure that, “Places API” is enabled in the “Services” pane of the Google console.


10. Add Android Support library to this project

By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :

  • Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
  • Right click this project
  • Then from popup menu, Click “Android Tools -> Add Support Library “

11. Update the file res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">LocationNearby</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="str_btn_find">Find</string>

    <string-array name="place_type">
        <item>airport</item>
        <item>atm</item>
        <item>bank</item>
        <item>bus_station</item>
        <item>church</item>
        <item>doctor</item>
        <item>hospital</item>
        <item>mosque</item>
        <item>movie_theater</item>
        <item>hindu_temple</item>
        <item>restaurant</item>
    </string-array>

    <string-array name="place_type_name">
        <item>Airport</item>
        <item>ATM</item>
        <item>Bank</item>
        <item>Bus Station</item>
        <item>Church</item>
        <item>Doctor</item>
        <item>Hospital</item>
        <item>Mosque</item>
        <item>Movie Theater</item>
        <item>Hindu Temple</item>
        <item>Restaurant</item>
    </string-array>
</resources>

Note : Defining string arrays to populate Spinner Widget with Place types.


12. Update the layout file res/layout/activity_main.xml


<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"
    tools:context=".MainActivity" >

    <Spinner
        android:id="@+id/spr_place_type"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_alignParentTop="true" />

    <Button
        android:id="@+id/btn_find"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/spr_place_type"
        android:text="@string/str_btn_find" />

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/spr_place_type"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>


13. Create a new class namely “PlaceJSONParser” in the file src/in/wptrafficanalyzer/locationnearby/PlaceJSONParser.java


package in.wptrafficanalyzer.locationnearby;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class PlaceJSONParser {

    /** Receives a JSONObject and returns a list */
    public List<HashMap<String,String>> parse(JSONObject jObject){

        JSONArray jPlaces = null;
        try {
            /** Retrieves all the elements in the 'places' array */
            jPlaces = jObject.getJSONArray("results");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /** Invoking getPlaces with the array of json object
        * where each json object represent a place
        */
        return getPlaces(jPlaces);
    }

    private List<HashMap<String, String>> getPlaces(JSONArray jPlaces){
        int placesCount = jPlaces.length();
        List<HashMap<String, String>> placesList = new ArrayList<HashMap<String,String>>();
        HashMap<String, String> place = null;

        /** Taking each place, parses and adds to list object */
        for(int i=0; i<placesCount;i++){
            try {
                /** Call getPlace with place JSON object to parse the place */
                place = getPlace((JSONObject)jPlaces.get(i));
                placesList.add(place);

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        return placesList;
    }

    /** Parsing the Place JSON object */
    private HashMap<String, String> getPlace(JSONObject jPlace){

        HashMap<String, String> place = new HashMap<String, String>();
        String placeName = "-NA-";
        String vicinity="-NA-";
        String latitude="";
        String longitude="";

        try {
            // Extracting Place name, if available
            if(!jPlace.isNull("name")){
                placeName = jPlace.getString("name");
            }

            // Extracting Place Vicinity, if available
            if(!jPlace.isNull("vicinity")){
                vicinity = jPlace.getString("vicinity");
            }

            latitude = jPlace.getJSONObject("geometry").getJSONObject("location").getString("lat");
            longitude = jPlace.getJSONObject("geometry").getJSONObject("location").getString("lng");

            place.put("place_name", placeName);
            place.put("vicinity", vicinity);
            place.put("lat", latitude);
            place.put("lng", longitude);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return place;
    }
}

Note  : This class parses the Google Places in JSON format and returns a List object.


14. Update the class “MainActivity” in the file src/in/wptrafficanalyzer/locationnearby/MainActivity.java


package in.wptrafficanalyzer.locationnearby;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;

import org.json.JSONObject;

import android.app.Dialog;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity implements LocationListener{

    GoogleMap mGoogleMap;
    Spinner mSprPlaceType;

    String[] mPlaceType=null;
    String[] mPlaceTypeName=null;

    double mLatitude=0;
    double mLongitude=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Array of place types
        mPlaceType = getResources().getStringArray(R.array.place_type);

        // Array of place type names
        mPlaceTypeName = getResources().getStringArray(R.array.place_type_name);

        // Creating an array adapter with an array of Place types
        // to populate the spinner
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, mPlaceTypeName);

        // Getting reference to the Spinner
        mSprPlaceType = (Spinner) findViewById(R.id.spr_place_type);

        // Setting adapter on Spinner to set place types
        mSprPlaceType.setAdapter(adapter);

        Button btnFind;

        // Getting reference to Find Button
        btnFind = ( Button ) findViewById(R.id.btn_find);

        // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();

        }else { // Google Play Services are available

            // Getting reference to the SupportMapFragment
            SupportMapFragment fragment = ( SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

            // Getting Google Map
            mGoogleMap = fragment.getMap();

            // Enabling MyLocation in Google Map
            mGoogleMap.setMyLocationEnabled(true);

            // Getting LocationManager object from System Service LOCATION_SERVICE
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

            // Creating a criteria object to retrieve provider
            Criteria criteria = new Criteria();

            // Getting the name of the best provider
            String provider = locationManager.getBestProvider(criteria, true);

            // Getting Current Location From GPS
            Location location = locationManager.getLastKnownLocation(provider);

            if(location!=null){
                onLocationChanged(location);
            }

            locationManager.requestLocationUpdates(provider, 20000, 0, this);

            // Setting click event lister for the find button
            btnFind.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    int selectedPosition = mSprPlaceType.getSelectedItemPosition();
                    String type = mPlaceType[selectedPosition];

                    StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
                    sb.append("location="+mLatitude+","+mLongitude);
                    sb.append("&radius=5000");
                    sb.append("&types="+type);
                    sb.append("&sensor=true");
                    sb.append("&key=YOUR_API_KEY");

                    // Creating a new non-ui thread task to download json data
                    PlacesTask placesTask = new PlacesTask();

                    // Invokes the "doInBackground()" method of the class PlaceTask
                    placesTask.execute(sb.toString());

                }
            });

        }

    }

    /** A method to download json data from url */
    private String downloadUrl(String strUrl) throws IOException{
        String data = "";
        InputStream iStream = null;
        HttpURLConnection urlConnection = null;
        try{
            URL url = new URL(strUrl);

            // Creating an http connection to communicate with url
            urlConnection = (HttpURLConnection) url.openConnection();

            // Connecting to url
            urlConnection.connect();

            // Reading data from url
            iStream = urlConnection.getInputStream();

            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));

            StringBuffer sb  = new StringBuffer();

            String line = "";
            while( ( line = br.readLine())  != null){
                sb.append(line);
            }

            data = sb.toString();

            br.close();

        }catch(Exception e){
            Log.d("Exception while downloading url", e.toString());
        }finally{
            iStream.close();
            urlConnection.disconnect();
        }

        return data;
    }

    /** A class, to download Google Places */
    private class PlacesTask extends AsyncTask<String, Integer, String>{

        String data = null;

        // Invoked by execute() method of this object
        @Override
        protected String doInBackground(String... url) {
            try{
                data = downloadUrl(url[0]);
            }catch(Exception e){
                Log.d("Background Task",e.toString());
            }
            return data;
        }

        // Executed after the complete execution of doInBackground() method
        @Override
        protected void onPostExecute(String result){
            ParserTask parserTask = new ParserTask();

            // Start parsing the Google places in JSON format
            // Invokes the "doInBackground()" method of the class ParseTask
            parserTask.execute(result);
        }

    }

    /** A class to parse the Google Places in JSON format */
    private class ParserTask extends AsyncTask<String, Integer, List<HashMap<String,String>>>{

        JSONObject jObject;

        // Invoked by execute() method of this object
        @Override
        protected List<HashMap<String,String>> doInBackground(String... jsonData) {

            List<HashMap<String, String>> places = null;
            PlaceJSONParser placeJsonParser = new PlaceJSONParser();

            try{
                jObject = new JSONObject(jsonData[0]);

                /** Getting the parsed data as a List construct */
                places = placeJsonParser.parse(jObject);

            }catch(Exception e){
                Log.d("Exception",e.toString());
            }
            return places;
        }

        // Executed after the complete execution of doInBackground() method
        @Override
        protected void onPostExecute(List<HashMap<String,String>> list){

            // Clears all the existing markers
            mGoogleMap.clear();

            for(int i=0;i<list.size();i++){

                // Creating a marker
                MarkerOptions markerOptions = new MarkerOptions();

                // Getting a place from the places list
                HashMap<String, String> hmPlace = list.get(i);

                // Getting latitude of the place
                double lat = Double.parseDouble(hmPlace.get("lat"));

                // Getting longitude of the place
                double lng = Double.parseDouble(hmPlace.get("lng"));

                // Getting name
                String name = hmPlace.get("place_name");

                // Getting vicinity
                String vicinity = hmPlace.get("vicinity");

                LatLng latLng = new LatLng(lat, lng);

                // Setting the position for the marker
                markerOptions.position(latLng);

                // Setting the title for the marker.
                //This will be displayed on taping the marker
                markerOptions.title(name + " : " + vicinity);

                // Placing a marker on the touched position
                mGoogleMap.addMarker(markerOptions);
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onLocationChanged(Location location) {
        mLatitude = location.getLatitude();
        mLongitude = location.getLongitude();
        LatLng latLng = new LatLng(mLatitude, mLongitude);

        mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(12));
    }

   @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
    }
}

Note : At line 128, replace “YOUR_API_KEY” with the api key obtained in Step 9.


15. Update the file AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.wptrafficanalyzer.locationnearby"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <permission
        android:name="in.wptrafficanalyzer.locationnearby.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="in.wptrafficanalyzer.locationnearby.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="in.wptrafficanalyzer.locationnearby.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR_API_KEY"/>

    </application>

</manifest>

Note : At line 43, replace “YOUR_API_KEY” with the api key obtained in step 8.


16. Screenshot of the application

Screenshot of the application in execution

Figure 7 : Screenshot of the application in execution


17. Download


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: , , , , , , ,

209 Responses to Showing nearby places using Google Places API and Google Map Android API V2

  1. athena on March 6, 2013 at 12:53 am

    THANK YOU SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCH!!! I WAS TRUING TO DO THAT IN WEEKS!!!! IT’S WORKING PERFECTLY!!!

    • Ajaykumar on May 16, 2013 at 10:49 am

      Hai pls send me the code ….iam downloading that code but it hace lot of errors..pls sir send d code

      • mahmoud on May 5, 2016 at 10:43 pm

        me too please

    • Aditya on January 5, 2016 at 4:14 pm

      can you please send me your code? the code given here is not correctly working for me ….. my id : bommireddipalliaditya@gmail.com

    • snehasish halder on February 4, 2016 at 2:02 pm

      i am trying to do that in android 6.0 but its not working .pls help me.

    • pavan on May 27, 2016 at 7:11 pm

      can you tell me what to do if i want to show a fixed area in my app not all the world when i entered into that fragment..

  2. HaarDik SolankI on March 6, 2013 at 1:01 am

    Mrng Sir….

    I m not sure this is working o nt….
    when i go to this link maps.googleapis.com/maps/api/place/nearbysearch/json?
    ..it shows request denied…
    sir i wud lyk to know..why is it shwing request denied?
    jst for knowledge..

    Thank u So much Sir…

    • sanjay on June 22, 2015 at 5:25 pm

      you have to switch on the google place service on ..so it will remove the error

    • sanjay on June 23, 2015 at 11:27 am

      firstly switch on google place service and map service also ..then it will remove

    • Divaker on October 9, 2015 at 2:34 pm

      this link is not working: maps.googleapis.com/maps/api/place/nearbysearch/json?
      ..it shows request denied…
      Please if You got any json link or project to get Nearest Hospital please send it

  3. athena on March 6, 2013 at 10:06 pm

    You must use your own API key (for browser apps and for android apps). It works great!

    • Komal Nikhare on October 29, 2013 at 8:36 pm

      Sir I insert my own key in to that code but when i run this the simulator shows message that “unfortunately application has stopped” .
      Would you help me why this app not run

      • amiyo on January 18, 2014 at 5:57 pm

        i am face same problem …sir please reply this

        • Amiyo on March 9, 2014 at 12:57 pm

          Now i overcome this problem

          • EMRAH on March 31, 2014 at 12:42 pm

            Hi,did you fixed it,please write.

          • Ryan on July 30, 2015 at 6:22 pm

            work with android android studio.eclipse not working in this case

      • Navin on April 1, 2015 at 3:08 pm

        Did u change the package name in manifest

  4. HaarDik SolankI on March 7, 2013 at 12:00 am

    Hey Thanks Sir…

    Would u please tell me How much will i be charged for google places api key…..?????

    Thank U So much Sir…!!

  5. athena on March 7, 2013 at 2:29 am

    Nothing it’s free. You are welcome!

    • george on March 7, 2013 at 4:06 am

      But it is having some usage limits. Please see the link given below :

      developers.google.com/places/policies#usage_limits

  6. muli on March 11, 2013 at 8:26 pm

    hello,
    very good tutorials!!

    can you see a reason why this not working? (the key is from my api console)

    maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.1145134,34.8269532&radius=5000&types=atm&sensor=true&key=MY_KEY

    thanks in advance

    muli

    • george on March 11, 2013 at 8:37 pm

      Please ensure that, you created a “Browser key” from Google API console and you enabled “Places API” in “Services” menu.

      • pooja on May 3, 2015 at 6:22 pm

        sir can you tell me which url i need to give while generating browser key

        because when i run this application ,nothing will happened when click on button. so plz. tell me what is the issue

      • pooja on May 3, 2015 at 6:37 pm

        sir can you tell me which url i need to give while generating browser key

        because when i run this application ,nothing will happened when click on button. so plz. tell me what is the issue
        it does not show any marker. plz plz. help me .

    • sanjay on June 22, 2015 at 5:27 pm

      maps.googleapis.com/maps/api/place/search/json?location=32.1145134,34.8269532&radius=5000&types=atm&sensor=true&key=MY_KEY

      use this nearbysearch instead of it searach only

  7. Sidd on March 12, 2013 at 2:20 am

    THANK YOU SOOO MUCH FOR THIS !!!!!!

    I’ve been Googling a SIMPLE answer to solve this ALL day, WHY can’t people write up something as simple as this.

    You’ve definitely helped me a lot, thanks!

  8. eesha on March 12, 2013 at 3:05 pm

    i just need to show nearby restaurants on map…using google places api. how can i do that?

  9. Luis on March 29, 2013 at 1:03 am

    Hey, this is a great post. For some reason I am not getting any of the markers showing up when i press FIND. The listener for the Find button is working just fine but not sure why the markers aren’t showing up. I logged out sb.toString() and it shows that everything logs out just fine. So I know the details are received. Not sure why the markers aren’t showing up. I will continue to look into this in the mean time and send you another email if I get it to work. Thanks

    Luis

  10. jj on April 2, 2013 at 2:53 am

    This tutorial is just too Good.Thanks a lot.It saved my time.Can you also tell me how can I show the route to this nearest places selected with the distance specified,so that the users could choose the nearest place ?
    Hope you can help.

    • xavi on August 9, 2013 at 7:22 pm

      Hi, JJ

      Did you achieve to draw the route to these places? I’m strugglin a bit with that.

      Thanks in advance :)

  11. Lawis on April 6, 2013 at 10:38 pm

    Thank you.
    For some reason I am not getting any of the markers showing up when i press FIND.

    • Lawis on April 6, 2013 at 11:09 pm

      It works.

      • Luis on April 14, 2013 at 11:26 am

        What was the problem? I’m having the same problem. Markers are t showing up at all

        • Mansour on January 25, 2015 at 6:41 pm

          Please mr Luis.. help how you solve to show marker???

      • amir on September 3, 2013 at 4:11 pm

        how did u solve this problem sir. when i press find nothing happens.

    • Amna on May 14, 2013 at 11:30 pm

      I am also not getting any of the markers. I am using the correct API key….any ideas???
      Thanks

  12. gowtham on April 10, 2013 at 6:15 pm

    Hi,George .. This is great Stuff ..Thank you very much .
    I ran it but its not showing the markers.I got my current location,And i got the following Errors:

    1.
    registerListener :: handle = 0 name= BMA222 delay= 20000 Listener= maps.h.a@405e8f28

    2.
    unregisterListener:: all sensors, listener = maps.h.a@405e8f28

    Please could you help me ? Thanks a lot in advance

    • gowtham on April 10, 2013 at 6:32 pm

      Yes,Sorry for Disturbing I added API key from “Key for Android apps (with certificates)” Instead of “Key for browser apps (with referers)” Now It works great .Thank you very very much george! For this great tutorial .

  13. Manasa on April 13, 2013 at 12:46 pm

    Perfectly it Worked!!! Thank you so much

  14. noussa on April 16, 2013 at 5:39 am

    how can i activate api places please

  15. jazz1 on April 18, 2013 at 8:42 am

    Hi, I followed the whole tutorial which is really helpful. But when i deploy it on the emulator, it says “you need google play services”.

    Can you suggest what can be the reason for not detecting the google API.
    I have done the following:
    1. placed the google-play-services_lib in my workspace.
    2. Included it in my project library.

    Please help. Thanks

    • jazz1 on April 18, 2013 at 12:55 pm

      i just realized that the google play services dont work on emulator..tried it on my android phone! and its working.!! thank u so much! your code rocks….

  16. Eric Nguyen on April 21, 2013 at 9:40 pm

    Millions of thanks to you George!

    Your tutorial is up-to-date, cover the right scope (not too complicated, not too simple task) and it explains the 2 different keys needed for Google Maps Android API and Places API (my chief confusion last few days).

    All the best!

  17. somish on April 25, 2013 at 12:23 pm

    hi i see your demo app but i have one question …after getting all marker near by place .. i wann to put intent for description of that marker to new page so how i can add marker with specific id not marker.getId() i mean i wann to change default marker id to specific id how i can do this

    • Dominick on July 19, 2013 at 9:49 pm

      can you show me the example how you put the marker in? i am a student and is quite new to these things many thanks.

    • Dominick on July 20, 2013 at 8:58 pm

      this tutorial is good man real good but 1 problem is i till now still cant figure how to add marker into it can any 1 please show me an example on how to do it please.

      • george on July 20, 2013 at 9:50 pm

        Hi Dominick,
        I am not understanding your real problem.

  18. Chien on April 30, 2013 at 5:40 pm

    Hello!!
    I use your code and search in Chinese
    But nothing returned
    How can I improve with your code?
    Please help…
    Thank you.

  19. Pal on May 2, 2013 at 4:32 pm

    Hiii .. first of all Thanks for providing such a nice explanation :)
    Doubt :
    What is the proper format to put multiple ‘place_type’ in tag, corresponding to a single ‘place_type_name’. Like I want :
    atm bank
    corresponding to
    AtmBank
    to be something like this :
    atm,bank
    corresponding to :
    Bank Outlets
    So, I want to know the proper format to write ‘atm,bank’. This comma thing ‘,’ is wrong.
    Thanks in advance !

    • george on May 3, 2013 at 1:21 pm

      Hai Pal,
      Separate types with a pipe symbol (type1|type2|etc)

  20. victor on May 3, 2013 at 1:43 pm

    Perfectly it Worked!!! Thank you so much

  21. Vishak on May 3, 2013 at 1:50 pm

    setContentView(R.layout.activity_main);

    activity_main cannot be resolved. Please help me.

    • george on May 3, 2013 at 2:05 pm

      Please ensure that, the class MainActivity is not importing “android.R”

      • Vishak on May 3, 2013 at 2:10 pm

        Thank you .!

  22. Vishak on May 3, 2013 at 2:09 pm

    It shows maps and current location. But on clicking the find button it shows nothing. I tried changing the radius also.
    Help

    • Zulqarnain Alam on May 3, 2013 at 3:18 pm

      Thanks alot Sir you have solved my problem,,,

      • Vishak on May 3, 2013 at 6:09 pm

        But my problem is not solved. What changes have you done to the code>?

        • george on May 3, 2013 at 7:21 pm

          Hi Vishak,

          Please ensure the following :

          => You have enabled Places API service in Google APIs console

          => Created “Browser Key” as key for Places API from Google APIs console

          • usha on September 24, 2013 at 2:45 pm

            Sir,I have also same problem.on clicking the find button it shows nothing..after shows “This apps wont run unless you update google play service”.nothing happen.i m putting correct API keys and enable Places API but nothing work sir,Kinldy give solution

  23. Zulqarnain Alam on May 7, 2013 at 1:17 pm

    Thank alot Sir now i don’t need any search i will only share my problems with you,,,

  24. Zulqarnain Alam on May 7, 2013 at 1:28 pm

    Sir when I click find button it doesn’t do any thing,plz help

  25. Zulqarnain Alam on May 7, 2013 at 1:42 pm

    Sir when I click find button it doesn’t do any thing,plz help,
    Sir it also give me error on following line in layout.xml file.
    <fragment xmlns:android="http://schemas.android.com/apk/res/android&quot;

    • george on May 7, 2013 at 5:23 pm

      Hi,

      Are you getting any hint on error message in Logcat?

      In the mean time, please ensure the following :

      => You have enabled Places API service in Google APIs console

      => Created “Browser Key” as key for Places API from Google APIs console

  26. Radhouene on May 7, 2013 at 6:56 pm

    VERY Good tutorial but i don’t know why there is no markers :/ is there some solutions ???

  27. sarath on May 16, 2013 at 9:55 pm

    Thank you for your good tutorial,But i splitted your MainActivity.java into two first class download the data and second class show the map and markers so i need to send the list value to the next intent what should i do now?

  28. Vivek adhikari on May 23, 2013 at 5:25 pm

    Hello dear,

    Thanks for such a nice tutorial.

    I need to ask one thing why places are not appearing in my map, it is only showing my location, even FIND is not doing anything.

    I have used generated :

    – Key for browser apps (with referers)
    – Key for Android apps (with certificates)

    NEED HELP. As soon as possible.

    Thanks.

  29. eman on May 23, 2013 at 8:35 pm

    Hi,
    i am located in Egypt, and i have a question please, i executed your code following all steps in the tutorial, but when i press in find button there is not
    places appear nearby me, i do not know what is the problem, and another question for places API key; when i create new android key
    i see 2 keys created 1 for android app and another 1 for browser key (i made places API on in services) does this key used for places?
    and where i should put it in my Application ? in replacement of Google maps key or what ?
    Thanks appreciate your help.

    • george on May 23, 2013 at 9:08 pm

      Browser API Key : This is the key obtained in step 9 and use it in the line 128 of the class MainActivity.

      Android API Key : This is the key obtained in step 8 and use it in the line 43 of the file AndroidManifest.xml

      • Ahmed Basiouny on May 24, 2013 at 4:49 am

        Thanks very much, this solved the problemm, actually we are working together :) but i have another question please how can i show the places in a list ? what i want to do is show places in a list then if i pressed on any item it will draw a route from my current location to this place?
        Thanks in advance

        • Nikz Arkz on May 28, 2016 at 9:11 am

          have you resolved this problem? Actually i have the same problem of showing places in a list then if i pressed on any item it will draw a route from my current location to this place.Can you please tell me a way of doing it? Thank you

  30. asmaa on May 26, 2013 at 6:54 pm

    hi , how can return nearby places for one place such as bus station only please help me and thnx in advance

  31. Sam on May 29, 2013 at 1:36 am

    Sir!
    very nice tutorial..
    my project is showing current location on map but when i click any place type in spinner e.g banks it does not show any results, plz tell me how can I solve the issue?????

    Thanks in advance

  32. Tinou on May 30, 2013 at 3:07 am

    Hi,
    Thanks for such a nice tutorial
    when I click find button it doesn’t do any thing ( Pleaaase Help )
    I check two key several times ….

    • george on May 30, 2013 at 2:27 pm

      Hi Tinou,
      Please ensure that, “Places API” is enabled in the “Services” pane of the Google console.

      • Tinou on May 30, 2013 at 11:50 pm

        Hi,
        yes it is enabled,
        please it’s urgent

        • george on May 31, 2013 at 6:33 am

          Hi,
          Print the value of the StringBuffer variable sb of MainActivity class in Logcat to get the url and enter it in a web browser to see any places return?

          • Tinou on May 31, 2013 at 11:43 pm

            Hi george,
            it’s good, it works I create a new email address and I generate a new key …

            Now I want to display the route when I select a location.

            please help me this is really urgent it is for my final project study.

  33. Jack on May 31, 2013 at 1:52 pm

    Unable to resolve superclass of L

  34. Moe on June 2, 2013 at 1:38 am

    Hi, first thank you for this helpful tutorial, second, my maps is working fine so I assume that the Google Maps Android API is working perfectly, though I don’t think the place is working in my maps, I obtained it for the google api’s consol website by clicking on “Generate new browser key..” and I’ve put in in line 128 as you showed in the tutorial, still not working. Is it because that I should specify a name for a website when I click generate new browser key or what? and if yes what URL should I enter?

    • george on June 2, 2013 at 7:13 am

      Hi Moe,
      On generating browser key, we can keep the url referer field as blank.

      • Moe on June 2, 2013 at 7:07 pm

        Thank you so much man, such an amazing tutorial, it’s working perfectly now. I have a question, how the map know the places I input in the strings file? Because I’m trying to give it a name of a shop for example “Walmart” it’s not showing in the map?

  35. Canberk on June 2, 2013 at 10:45 pm

    Hi George. First of all thank you for this tutorial. I have a problem please help me. I can see my location (it works) but i dont get any reaction when i touch find button. I have been try to fix this problem for a long time. Its my senior project. Please help me. Thank you.

  36. Tinou on June 3, 2013 at 10:52 pm

    Hi George,

    I want to display the route when I select a location.

    please help me this is really urgent it is for my final project study.

  37. Jack on June 4, 2013 at 2:56 pm

    Thank u very much for this tutorila
    Would you please tell how to show the details of those places nearby?

  38. asia on June 4, 2013 at 5:15 pm

    can u explain to me the part of on post execute when i return the hashmap in list and then get the values in hash map i can’t understand this exactly and how can i put latlng only in list?

    • george on June 6, 2013 at 6:58 pm

      “list” is an ArrayList of HashMap objects where each HashMap object represents a place with keys, place_name, vicinity, lat and lng. So “list” contains all the nearby places. This array list is created in the class PlaceJSONParser.

  39. Ceren on June 5, 2013 at 12:56 am

    Hi george;I dont get the markers on the map.What the reason of this problem.everything is allright,I dont get error but only the markers is not visible.So important for me please help.thanks for everythng.

    • george on June 5, 2013 at 5:37 am

      Hello Ceren,
      Just try to recreate the keys and use it in the application

  40. Fian on June 7, 2013 at 5:58 pm

    Hi george .. how to display the nearest location by using its own database?

  41. Hung on June 17, 2013 at 12:01 pm

    Hi man, I really appreciate your work.
    Many thanks.

  42. Amina on June 19, 2013 at 11:08 pm

    i just need to show nearby mosque on map…using google places api. how can i do that?

  43. mark on June 24, 2013 at 3:15 pm

    Am getting the routes and the places using the above article but in background my map is not visible it just shows me plain grey color background with the places and it routes…

    Why am not getting map in background

  44. mecca on July 9, 2013 at 4:08 pm

    I need to ask one thing why places are not appearing in my map, it is only showing my location, FIND is generating this error.

    07-09 13:26:21.989: D/Exception while downloading url(6520): java.net.UnknownHostException: maps.googleapis.com
    07-09 13:26:21.989: D/Background Task(6520): java.lang.NullPointerException
    07-09 13:26:22.029: D/Exception(6520): java.lang.NullPointerException

  45. mecca on July 9, 2013 at 4:44 pm

    Figured out my problem Places API was not enabled.

  46. Linea on July 12, 2013 at 2:48 pm

    HELP! Application force closed! Error is at ParserTask.onPostExecute().

    FATAL EXCEPTION: main
    java.lang.NullPointerException
    com.android.nearbyhawker.MainActivity$ParserTask.onPostExecute(MainActivity.java:281)
    com.android.nearbyhawker.MainActivity$ParserTask.onPostExecute(MainActivity.java:1)
    android.os.AsyncTask.finish(AsyncTask.java:631)
    android.os.AsyncTask.access$600(AsyncTask.java:177)
    android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
    android.os.Handler.dispatchMessage(Handler.java:99)
    android.os.Looper.loop(Looper.java:137)
    android.app.ActivityThread.main(ActivityThread.java:4745)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:511)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    dalvik.system.NativeStart.main(Native Method)

    Any idea what happened? :(

    Thank you!

    • Ashwini on August 8, 2013 at 3:47 pm

      hi…
      I’m also facing the same issue as above, that is

      08-08 15:46:38.882: E/AndroidRuntime(27602): FATAL EXCEPTION: main
      08-08 15:46:38.882: E/AndroidRuntime(27602): java.lang.NullPointerException
      08-08 15:46:38.882: E/AndroidRuntime(27602): at my.places.nearby.PlacesNear$ParserTask.onPostExecute(PlacesNear.java:242)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at android.os.AsyncTask.finish(AsyncTask.java:631)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at android.os.AsyncTask.access$600(AsyncTask.java:177)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at android.os.Handler.dispatchMessage(Handler.java:99)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at android.os.Looper.loop(Looper.java:153)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at android.app.ActivityThread.main(ActivityThread.java:5086)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at java.lang.reflect.Method.invokeNative(Native Method)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at java.lang.reflect.Method.invoke(Method.java:511)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
      08-08 15:46:38.882: E/AndroidRuntime(27602): at dalvik.system.NativeStart.main(Native Method)

      • Linear on August 8, 2013 at 10:13 pm

        hey Ashwini, i already solved the problem. NullPointerException at onPostExecute indicates that your app didn’t retrieve any data from Google database via Google Places API. Hmm..i think you have to double check your Places API’s configuration. You should create a new Browser key instead of a new Android key from Google APIs Console. And I realized that when you are creating an either Android key or Browser key, you should just click on create button without keying any certificate fingerprints or package, so that the key generated can be used by any apps.

        • Dipesh Patel on September 27, 2013 at 7:13 pm

          i am getting this king of errors..can you please help me??????

          09-27 19:11:34.691: E/AndroidRuntime(23165): FATAL EXCEPTION: main
          09-27 19:11:34.691: E/AndroidRuntime(23165): java.lang.NullPointerException
          09-27 19:11:34.691: E/AndroidRuntime(23165): at com.example.travelapp.MainActivity$ParserTask.onPostExecute(MainActivity.java:270)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at com.example.travelapp.MainActivity$ParserTask.onPostExecute(MainActivity.java:1)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at android.os.AsyncTask.finish(AsyncTask.java:602)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at android.os.AsyncTask.access$600(AsyncTask.java:156)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at android.os.Handler.dispatchMessage(Handler.java:99)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at android.os.Looper.loop(Looper.java:137)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at android.app.ActivityThread.main(ActivityThread.java:4517)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at java.lang.reflect.Method.invokeNative(Native Method)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at java.lang.reflect.Method.invoke(Method.java:511)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
          09-27 19:11:34.691: E/AndroidRuntime(23165): at dalvik.system.NativeStart.main(Native Method)

  47. xavi on August 9, 2013 at 4:59 pm

    Thank you so much for this tutorial. It’s been incredibly helpfull to me!

  48. Aravin on August 14, 2013 at 12:41 pm

    Hi george i download your code run in my device it running fine but when i choose the place like atm,bank nothing will be displayed can you help me to solve this.

    • George Mathew on August 14, 2013 at 1:32 pm

      Hi Aravin,
      Please print the downloaded data ( before parsing ) in logcat to check whether it contains any place or not for atm, bank etc.

      • Aravin on August 14, 2013 at 2:22 pm

        It shows like the following.
        “debug_info”:[]
        “html_attributions”:[]
        “results”:[]
        “status”:”request denied”

  49. Aravin on August 14, 2013 at 2:44 pm

    Thank you george it worked fine . Really nice tut and simple to understand.

  50. amit on August 20, 2013 at 1:00 pm

    thanks sir,I am new programer in android field and your examples really help a lot.

  51. vignesh on August 20, 2013 at 3:17 pm

    Hi sir,
    Thank you so much for this tutorial.

    While running in the Emulator, its displaying error msg as.. This app won’t run unless you update the google play services. And while clicking update button it shows as unfortunately this app has stopped. Pls help me solve tis problem

    • amir on September 3, 2013 at 3:49 pm

      hi vignesh. i also have this same problem. did u solve yours? please tell me how if u did. thanking you.

  52. hanis on September 1, 2013 at 1:19 pm

    Sweet..the code that I’m looking for..easy to follow and replicate..much appreciated..

  53. amir on September 3, 2013 at 3:19 pm

    hello sir
    thanks for such a nice tutorial. it was helpful.
    the only problem i have is that when i run the application on my emulator, it says i have to update google play services before the app will run. i check my SDK manager and my google play is up-to-date. please help me with this problem. thanking you

    • amir on September 3, 2013 at 3:47 pm

      and also after is says i should update google play services before i could run the app, i clicked the update button on the interface of the app but got this message: “unfortunately locationnearby has stopped” please help me sir

      • amir on September 3, 2013 at 8:15 pm

        i fix the problem thank you sir

        • kian on February 28, 2014 at 10:33 pm

          Hi Amir,

          Can I know how do you fix the problem please. Thanks.

  54. amir on September 3, 2013 at 8:14 pm

    hello sir. thanks for this tutorial. it has been helpful. however, when i try click on find button on the emulator, nothing happens. i checked the logcat and found the following message:
    googgle maps android API v2 only supports devices with OpenGL ES 2.0

  55. micheal on September 5, 2013 at 7:13 pm

    Hello George
    Very good tutoral.
    please can you tell me how to add google map search to this project. i have the code but i cant have two oncreate method on the same activity. please can you show me how to do this. either through email or posted here. thank you very much

  56. Jacks on September 11, 2013 at 9:29 pm

    Hi george, i have a question,

    How to manage exception when no internet connection. so when i click Find Button apps wont crash because of no connection.

  57. Vaishali on September 12, 2013 at 12:06 pm

    Hello,this working very well.thanks for this tutorial.
    How can i had my own marker for showing places instead of default markers?

  58. babu s on September 15, 2013 at 4:59 pm

    Hello,this is a great tutorial.I have few questions
    1.How to a polyline from current location to nearest marker ?
    2.How to draw a polyline from my current location to touched marker using on marker click listener ?
    Thamks in advance..

  59. usha on September 23, 2013 at 5:15 pm

    Hi sir,
    when i try click on find button on the emulator, nothing happens.
    I Enter correct API Keys and on Places API,but nothing happens..
    Kindly help me.

  60. mudit srivastava on October 18, 2013 at 11:06 am

    hello sir,
    i entered the api key but nothing is displaying on the screen, please help me

  61. mudit srivastava on October 22, 2013 at 10:58 am

    hello sir, when i run the code nothing is diplaying on the screen, no map and no location.please help me as soon as possible as i m developing some live application.

  62. mudit srivastava on October 22, 2013 at 11:00 am

    hello sir , please help me as nothing is displaying on the screen.

  63. Komal Nikhare on October 29, 2013 at 2:54 pm

    Hello sir…
    sir my question is that can i get particular place latitude and longitude by typing that place name as a text through this api

  64. Ashwini on October 30, 2013 at 5:54 pm

    I want to show the near tourist locations.how to add the place name of that..please reply me..
    for ex:if am in mysore ,it should mark on palace,K.R.S,etc..

  65. Jony on November 5, 2013 at 12:25 pm

    It indicates an error in the line:

    setContentView(R.layout.activity_main);

    R cannot be resolved to a variable

    Just copy the code and put my own keys, do I need to consider anything else?

  66. Clara on November 12, 2013 at 9:32 am

    Sir, i already follow your tutorial, already activate “Places API” & “Google Maps Android API v2″, and also using Key for browser apps (with referers). i’m running this sample on Genymotion. first it’s show the map with my current location with default marker. the problem is, when i select a place via spinner, e.g Hospital, the app is suddenly crash. on the logcat, it sayed java.lang.NullPointerException at com.example.app.Places_On_Resta_Map$ParserTask.onPostExecute. can you help me sir?? it’s for my collage project. thanks

    • John on February 27, 2014 at 12:52 pm

      I was having the same problem. Solved it from here stackoverflow.com/questions/21985449/asynctask-null-pointer-exception-google-places

  67. ganesh on January 8, 2014 at 12:16 pm

    when i using this application every thing is ok but i did it get my nearby placees.what should i do sir please help me

    • Saira Khan on September 19, 2014 at 7:08 pm

      Hi sir. Nearby places not displayed. GPS is on wifi is on and checked the log of sb. which was fine but List places was empty. how to make it work . what we missed. plz help

  68. hardik on January 17, 2014 at 4:54 pm

    hey really thank u so much

  69. kavitha on January 30, 2014 at 6:28 pm

    hi sir i want this code in pc version not in android,nw im dng project on maps so i hav to display the items in map when i click on the particular item like atm,shopping mall etc….help me out
    thank u

  70. Dharmik on January 31, 2014 at 5:17 pm

    Hello, Sir, this code is working fine and showing map on my device properly, so Google Map API working fine, but when i click on FIND button my application crash and showing the error
    AndroidRuntime(8116): at com.android4me.hotelsnearby.MainActivity$ParserTask.onPostExecute(MainActivity.java:251).
    I double check my Both API(Maps API and Place API) and placed at there proper place(in Menifest and MainActivtiy), I have tried also new created keys.
    I had also check the URL which is shown by LOGCAT by printing StringBuffer object variable, and pasted it in browser but it shows me following:
    {
    “html_attributions” : [],
    “results” : [],
    “status” : “ZERO_RESULTS”
    }
    Please help…

  71. şerif on February 2, 2014 at 5:01 pm

    Hello Sir,

    I downloaded your code and run with virtual device which run android 4.2 api17 with google api and no google api and it crashes where did I go wrong? could you tell me ?
    The Error Code : Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationnearby/in.wptrafficanalyzer.locationnearby.MainActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class fragment

    • Dharmik on February 3, 2014 at 12:58 pm

      Make sure you have following code in your menifest under application tag,

      • Dharmik on February 3, 2014 at 1:01 pm

        ” ”

        remove outer qoutes.

        • shoaib khan on April 8, 2014 at 12:39 am

          Same error in my code pls someone know about it

  72. vidyanand on February 11, 2014 at 3:01 am

    Hi sir,

    I am getting some error in String.xml file with this line-

    and in MainActivity.java file with this line-

    import android.widget.span class=”k52m04u77pn7″ id=”k52m04u77pn7_24″>widget</span.ArrayAdapter;

    Please give me some solution.

    Thank You,

  73. kian on February 28, 2014 at 10:39 pm

    Dear Sir,

    2 things need your help Sir.

    I got this error when trying to run the code that I download. “Unfortunately, LocationNearby has stopped.”

    I got the Google play services installed.

    It should not be related to the keys right? any idea how I can fix it?

    and which project build target do I suppose to choose? “Android 4.2.2 and above” or “Google API”

    Thanks.

  74. Moke on April 14, 2014 at 1:50 pm

    Hi, thank you .. working!

  75. Joshua on August 30, 2014 at 4:25 pm

    im getting Unfortunately, LocationNearby has stopped what should i do? im using genymotion_vbox86p_4.2.2_130923_154637 as my emulator

  76. khan on September 1, 2014 at 11:46 am

    hi, sir thank you sir its work good .great sir i need help from u if i whante to drwa a path from curent location to any place(e.g hotel if user click any hotel)path will be show. how can i did it plzzzzzzz sir

  77. Belal Ahmed khan on September 11, 2014 at 9:10 am

    Firs of all thanx for this nice tutorial George
    I am confused when we enable place in Google api console what web site we have to write there and at the time of creating browser key it also requierd website name which web site i have to put there

    • Belal Ahmed khan on September 11, 2014 at 9:25 am

      Sir please help me and when i click on marker it shows unfortunetly stop

  78. hisham on September 14, 2014 at 10:24 am

    A wonderful tutorial….Thanks indeed…it was sooooooooo helpful

  79. Said Nuri UYANIK on November 15, 2014 at 3:41 pm

    Thank you so so much bro, That helps me for my midterm project.

  80. Noor Afshan on November 16, 2014 at 9:37 pm

    Nice Tutorial. First time, I was using browser key and its not showing markers of selecting places. When I use server key instead of browser key then working fine :)

  81. seema on November 18, 2014 at 4:18 pm

    Sir,I am not getting result on find button click,and getting resource not found while debugging..

  82. ozcan on November 23, 2014 at 6:43 am

    I have but one problem, how do i get browser key api as you said in step 9.
    My project is perfectly running now but it doesnt show any places because i had to use android api key (which is stupid of course :D ) .

  83. Siddharth on December 1, 2014 at 11:04 am

    Sir, when I run the project after adding both api keys and following all the steps mentioned it shows unfortunately stopped,please help me on this

    12-01 00:33:55.840: E/AndroidRuntime(1002): FATAL EXCEPTION: main
    12-01 00:33:55.840: E/AndroidRuntime(1002): Process: in.wptrafficanalyzer.locationnearby, PID: 1002
    12-01 00:33:55.840: E/AndroidRuntime(1002): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
    12-01 00:33:55.840: E/AndroidRuntime(1002): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
    12-01 00:33:55.840: E/AndroidRuntime(1002): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
    12-01 00:33:55.840: E/AndroidRuntime(1002): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
    12-01 00:33:55.840: E/AndroidRuntime(1002): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)

  84. Noumenon72 on December 15, 2014 at 1:44 pm

    When I import this code into Android Studio 1.0.1, I get an unrecoverable error:
    * Project LocationNearby:C:\LocationNearby\project.properties:
    Library reference ..\google-play-services_lib could not be found
    Path is C:\LocationNearby\..\google-play-services_lib which resolves to C:\google-play-services_lib
    I tried to find this file in the SDK Manager, Extras, but I couldn’t.

  85. Joseph on December 19, 2014 at 3:30 pm

    Hello sir, if i want a particular location to show as the default map when lauched how can i do that sir?

    • brian on January 8, 2015 at 6:39 pm

      hello if i want to display the places in a list form. what would i do.. thank you

  86. Yatin Verma on January 12, 2015 at 2:59 pm

    Sir, i have used the source code in my project. I am getting the eror due to unable to start Activity :android.content.res.ResourceNOTFOUND Exception: String array resourceId.

    Can you Please tell why i am getting this error?

  87. Ankit Sharma on February 3, 2015 at 2:04 pm

    Hi Mr.Mathew, thnx for the tutorial.

    My question is that the above code returns only 20 results maximum and rest are ported to other pages of response.

    So how to read and display all the locations by reading all pages??

    Thanx in advance again

  88. Harshad Patel on February 17, 2015 at 8:40 pm

    awesome code, its working for me!!!! thank u for such a useful example, perfect result ;)

  89. Tanmay on February 23, 2015 at 6:03 pm

    Do we need to pay for getting the place api key

  90. nitesh on February 27, 2015 at 4:15 pm

    Hello Sir, Can u please tell me how to get the nearest police station phone number using google api, currently I m using place api it was returning the details about nearest police station, but phone number is still missing.
    Help me to sort this problem.

    Thanks

  91. burak on March 5, 2015 at 2:34 am

    sir hi,firstly thanks this tutorial ı run this but later when ı select item frpm spinner I get sendUserActionEvent mView== null error. do you know why?
    light me please

  92. asad mehmood on March 18, 2015 at 6:43 pm

    Sir, I just copy your whole to see how its working
    I replace my own Keys with yours in manifest and in MainActivity class.
    but Nothing is happening
    its giving Exception of
    “Unable to start activity component, android.view.inflateException:
    Binary XML file line #21: Error inflating class fragment”
    Please Reply as soon as possible :)

    • Omar on March 24, 2015 at 12:21 pm

      try this it has worked for me
      1- go to xml layout ” activity_main ” and changer the android version to use when rendering..etc to 13 , because the fragment needs version higher than 12 or equal to 12

      2- when you got to make api key for browser make sure to leave the refers box empty , dont refer anything .. (to show places)

      plus dont forget to insert the apikey for browser in the manifest

  93. Rameshbabu on March 23, 2015 at 7:16 pm

    Hi,

    Please help me to solve this given below my queries:

    1. Can I send rating parameters to Google server using Google places API’s?
    2. I have to pay Google for Google places & Google map services?

  94. vvvv on April 24, 2015 at 2:18 pm

    what i have to give as URL while creating browser key. pls any one reply me

  95. Mohamed Saber Abd Elhamed on April 26, 2015 at 2:36 am

    Sir, I just copy your whole to see how its working
    I replace my own Keys with yours in manifest and in MainActivity class.
    but when i want to find the details of a place the app crushes
    Thanks

  96. pooja on May 3, 2015 at 6:44 pm

    plz. tell me how to solve the problem ” it does not show any marker”

  97. shivani on May 7, 2015 at 2:53 pm

    Hey buddy
    I follow all ur steps even it shows everything gona fine in logcat but i am not able to view map its shows white screen with find bar and button having find
    I download projects from this site only and put my access keys at their perspective position but i am not able to see map pls can u tell me reason?

  98. vinuth on May 12, 2015 at 12:05 am

    Sir how do i get only the business places or malls,shops and so on?

  99. Purvi medawala on May 21, 2015 at 12:48 am

    Great tutorial!!! Worked perfectly!
    Thank you so much…it really helped me.
    Searched for many tutorials but ultimately this worked….

  100. leo on May 26, 2015 at 10:38 am

    list is returning null, i have tried with browser api as well

  101. Jain Nidhi on May 26, 2015 at 12:59 pm

    Hello,
    I got this error.

    The meta-data tag in your app’s AndroidManifest.xml does not have the right value. Expected 6587000 but found 0. You must have the following declaration within the element:

  102. madhu on May 29, 2015 at 12:59 pm

    Hello Sir,

    Thanks for your tutorial. Please help me to solve my issue.

    When i click on find button nothing is happened. Request denied message is appearing in my logcat.I added browser key and android key but i didn’t get nearby locations.

    Please help me sir

    Thank You.

  103. ram on June 4, 2015 at 4:50 pm

    Hi sir,

    Thanks for the tutorial. Please help me to solve my issue. I am getting current location but unable to get nearby locations. It gives me Request Denied error.

  104. vinoth on June 6, 2015 at 2:31 pm

    Hi,

    Greetings ,

    could you please help me because search option is not working .

  105. yoonmi on June 6, 2015 at 9:34 pm

    Hello Sir,
    Thanks for your help, eveything is good for your coding, very helpful to do my fyp, very appreciate it. =)
    But there is a problem for me, when my device disconnect any of the internet or gps, after i click on the Find button, it will appear an error that say “Unfortunately, your apps are stopped”, then after clicking OK will go exit.
    May I know is that any way to do like a pop out window will appear and tell to “Please connect to an internet and GPS” instead of this error.
    Thanks sir.

  106. Shikha on June 8, 2015 at 1:32 pm

    Hi,
    I am using this code map is showing current location but find is not working and it shows following error:
    maps.googleapis.com/maps/api/place/nearbysearch/json?location=22.69614649,75.86546569&radius=5000&types=doctor&sensor=false&key=AIzaSyCHR9JrsLUy8bcP27BCfdw0P_NZIYo6GQ0
    {“error_message”:”This API project is not authorized to use this API. Please ensure that this API is activated in the APIs Console: Learn more: https:\/\/code.google.com\/apis\/console”,”html_attributions”:[],”results”:[],”status”:”REQUEST_DENIED”}

  107. Yahya on June 10, 2015 at 7:29 am

    can somone help me please

    {
    “error_message” : “This IP, site or mobile application is not authorized to use this API key.”,
    “html_attributions” : [],
    “results” : [],
    “status” : “REQUEST_DENIED”
    }

  108. Amit Vats on July 9, 2015 at 9:24 am

    Thank you so much for your tutorial!!

    But after clicking find button i am not getting any marker on map. I did get browser and android key. my location on map is working fine.. Plz help me

  109. Ryan on July 26, 2015 at 2:40 am

    hello.

    i open it in emulator but says :google play service is not supported in you device .

    there is ok button below this text.when push it close the app and show this erro : 07-25 21:09:33.100: E/AndroidRuntime(2017): FATAL EXCEPTION: main
    : java.lang.NullPointerException
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1410)
    at android.app.Activity.startActivityForResult(Activity.java:3370)

  110. chan_jc on July 26, 2015 at 10:26 pm

    Sir,since the add event has been removed from the google place API since 2015, so how i going to do so?For example, an add extra info(event) about the discount/sale of the store/shop/cafe/restaurants.

  111. Ryan on August 6, 2015 at 4:42 pm

    hello.

    i want change ATM to gas station.how i can do that??

    thanks you…!

  112. Ryan on August 8, 2015 at 3:04 pm

    hello.

    brwoser key is android api key???

    how can i obtain a browser key??

  113. FABIO ANDRES SANCHEZ MEJIA on August 12, 2015 at 12:08 am

    Hello Sir George,

    I have a question, this example works perfect. When I insert the map at a Fragment (not v4) I have had many problems in my application I have three tabs and one of them will be the Map. Could you help me guiding me as I embed one FragmentActivity into a Tab using the commit () the Fragment or perhaps an example Maps on Fragments?

    Thank you very much Mr.

    Fabio.

  114. Ryan on August 19, 2015 at 2:27 am

    how i can i search for a specific place not a list of google supported places??

  115. Ronak Thakkar on September 3, 2015 at 5:10 pm

    This IP, site or mobile application is not authorized to use this API key. Request received from IP address ***.***.**.***, with empty referer

  116. Ronak Thakkar on September 3, 2015 at 5:10 pm

    can any 1 help me????

  117. Subhrojoy on September 15, 2015 at 9:36 pm

    There is an error R cannot be resolved to a variable . Can you tell me how to solve this problem .Thanks

  118. SAumyajit on October 9, 2015 at 12:46 pm

    How to fetch rating

  119. Siddhant on October 14, 2015 at 6:28 pm

    The data that is received from google places API which you have parsed from Json into a list object , can you save that data in your personal database to fetch the details of the place later from your own database ?
    Thanks

  120. ganesh on November 12, 2015 at 5:41 pm

    thank you for the tutorial.app runs perfectly but i am unable to find any places.it always shows map.what should i do. please help me on that issue.

  121. Amit on November 24, 2015 at 3:51 pm

    Sir,
    Recently google has changed it’s procedure for creating the API key. And in the documentation there is nothing about how to create API key. So please can you tell us how to create API key, because I tried with API key, server key and browser key. But no one key is working.
    Thanks in advance.

  122. amitshinde on January 11, 2016 at 10:17 pm

    Hi,

    I have downloaded the app and tried it. I installs well but when select a place it does not do anything. At first i thought it was the onclick listner intent.

    Let me know. I have tried using browserkeys as well…

  123. Vinay Agrahara on February 20, 2016 at 1:11 am

    i tried the above code but when i select the options from the spinner section markers(places like bank or hospital…) are not updating..

  124. Nishant on February 21, 2016 at 9:13 pm

    For people not getting any markers when pressing the FIND button,that is because the latitude’s & longitude’s value is still 0.0 & 0.0 respectively. What you need to do is to improvise the code so that it stores your current location explicitly. Then pressing the Find button will display the markers.

  125. Anish choudhary on February 21, 2016 at 9:26 pm

    Hello Sir,
    I have a got a problem.Everything is working fine but except one thing – Place Api. It’s not getting enabled and I am not able to solve this problem.
    Hope you will help me.
    and I really appreciate you for this code.
    and Thanks in advance !

  126. Shelly Tomar on February 29, 2016 at 3:00 pm

    Thank you so much for your tutorial. I am able to get my current location, but I am not able to see any markers and even after selecting ATM or airport from menu and clicking on “Find” button, no markers shows up.

    I am using correct Android key and Browser key. Please help.

  127. Zeeshan on March 14, 2016 at 1:59 am

    Sir i need some help regarding google map.
    I have a current location now i want to list all nearest location which is between my current location and around 50/100 kilometers using S.E/N.W. I am stuck that point from last 2 weeks. Any help would be really appreciate.

  128. Sandeep on March 14, 2016 at 7:47 pm

    Sir, I had downloaded ur code and fixed all the errors..but when I am running on eclipse it is unfortunatly stopped… Please give me suggestion to run it successfully… I need it very urgnt

  129. Mark on April 6, 2016 at 5:35 am

    Can someone please tell me what I must LOG to show the results ?

    I need to know if I’m receiving the data.

    Thanks

  130. Harshita on April 13, 2016 at 2:34 pm

    Hello,
    not getting any response while I am changing the data items (like ATM, Airport and all) from spinner. Application just showing the Map.
    So can you please help me, I am running this same code on Android Studio.
    Thanks in Advance.

  131. Vikash on April 25, 2016 at 1:18 pm

    sir, i m currently working on a google Map based application using android studio. In this application i want share some information within a radius, that radius are set by me.. sir i have no any idea how to do it.. plz help or guide me..

  132. vinay on April 27, 2016 at 4:12 pm

    i followed all instructions as you described abovve i am not getting any error or exception,but when i click on the find button nothing is happening,plese solve this problem..

  133. Asad on May 1, 2016 at 11:04 am

    Everything is working fine but map isn’t showing when activity is launched.
    Need Solution ASAP.

  134. manivel.m on May 2, 2016 at 1:40 pm

    google map locaton in android studio plz sir …………………

  135. ramandeep kaur on May 27, 2016 at 4:01 pm

    Great tutorial..solved my problem..Thank you

  136. Ramesh on June 29, 2016 at 3:15 pm

    Hi Good Evening,

    I need without gps finding acurate location for example i am ground floor to top floor how can write polyline in android

  137. Ashok on July 10, 2016 at 5:59 pm

    Sir, I’m facing an error..
    the error is in this line.
    mGoogleMap = fragment.getMap() ;
    how can i over come it ??
    pls help me :)

Leave a Reply to Amina Cancel reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner