Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Step by step,</p> <p><strong><em>Google place api are used to access near by landmark of anloaction</em></strong></p> <p><strong>Step 1</strong> : Go to API Console for obtaining the Place API </p> <p><a href="https://code.google.com/apis/console/">https://code.google.com/apis/console/</a></p> <p>and select on services tab</p> <p><img src="https://i.stack.imgur.com/oHiZd.jpg" alt="Service"></p> <p>on the place service </p> <p><img src="https://i.stack.imgur.com/fQSTB.jpg" alt="enter image description here"></p> <p>now select API Access tab and get the API KEY </p> <p><img src="https://i.stack.imgur.com/Xno1l.jpg" alt="enter image description here"></p> <p>now you have a API key for getting place </p> <hr> <p><strong>Now in programming</strong> </p> <p><strong>*Step 2 *</strong> : first create a class named <strong>Place.java</strong>. This class is used to contain the property of place which are provided by Place api.</p> <pre><code>package com.android.code.GoogleMap.NearsetLandmark; import java.util.logging.Level; import java.util.logging.Logger; import org.json.JSONException; import org.json.JSONObject; public class Place { private String id; private String icon; private String name; private String vicinity; private Double latitude; private Double longitude; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } public Double getLatitude() { return latitude; } public void setLatitude(Double latitude) { this.latitude = latitude; } public Double getLongitude() { return longitude; } public void setLongitude(Double longitude) { this.longitude = longitude; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getVicinity() { return vicinity; } public void setVicinity(String vicinity) { this.vicinity = vicinity; } static Place jsonToPontoReferencia(JSONObject pontoReferencia) { try { Place result = new Place(); JSONObject geometry = (JSONObject) pontoReferencia.get("geometry"); JSONObject location = (JSONObject) geometry.get("location"); result.setLatitude((Double) location.get("lat")); result.setLongitude((Double) location.get("lng")); result.setIcon(pontoReferencia.getString("icon")); result.setName(pontoReferencia.getString("name")); result.setVicinity(pontoReferencia.getString("vicinity")); result.setId(pontoReferencia.getString("id")); return result; } catch (JSONException ex) { Logger.getLogger(Place.class.getName()).log(Level.SEVERE, null, ex); } return null; } @Override public String toString() { return "Place{" + "id=" + id + ", icon=" + icon + ", name=" + name + ", latitude=" + latitude + ", longitude=" + longitude + '}'; } } </code></pre> <p>Now create a class named <strong>PlacesService</strong></p> <pre><code>package com.android.code.GoogleMap.NearsetLandmark; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.util.Log; public class PlacesService { private String API_KEY; public PlacesService(String apikey) { this.API_KEY = apikey; } public void setApiKey(String apikey) { this.API_KEY = apikey; } public List&lt;Place&gt; findPlaces(double latitude, double longitude,String placeSpacification) { String urlString = makeUrl(latitude, longitude,placeSpacification); try { String json = getJSON(urlString); System.out.println(json); JSONObject object = new JSONObject(json); JSONArray array = object.getJSONArray("results"); ArrayList&lt;Place&gt; arrayList = new ArrayList&lt;Place&gt;(); for (int i = 0; i &lt; array.length(); i++) { try { Place place = Place.jsonToPontoReferencia((JSONObject) array.get(i)); Log.v("Places Services ", ""+place); arrayList.add(place); } catch (Exception e) { } } return arrayList; } catch (JSONException ex) { Logger.getLogger(PlacesService.class.getName()).log(Level.SEVERE, null, ex); } return null; } //https://maps.googleapis.com/maps/api/place/search/json?location=28.632808,77.218276&amp;radius=500&amp;types=atm&amp;sensor=false&amp;key=&lt;key&gt; private String makeUrl(double latitude, double longitude,String place) { StringBuilder urlString = new StringBuilder("https://maps.googleapis.com/maps/api/place/search/json?"); if (place.equals("")) { urlString.append("&amp;location="); urlString.append(Double.toString(latitude)); urlString.append(","); urlString.append(Double.toString(longitude)); urlString.append("&amp;radius=1000"); // urlString.append("&amp;types="+place); urlString.append("&amp;sensor=false&amp;key=" + API_KEY); } else { urlString.append("&amp;location="); urlString.append(Double.toString(latitude)); urlString.append(","); urlString.append(Double.toString(longitude)); urlString.append("&amp;radius=1000"); urlString.append("&amp;types="+place); urlString.append("&amp;sensor=false&amp;key=" + API_KEY); } return urlString.toString(); } protected String getJSON(String url) { return getUrlContents(url); } private String getUrlContents(String theUrl) { StringBuilder content = new StringBuilder(); try { URL url = new URL(theUrl); URLConnection urlConnection = url.openConnection(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()), 8); String line; while ((line = bufferedReader.readLine()) != null) { content.append(line + "\n"); } bufferedReader.close(); } catch (Exception e) { e.printStackTrace(); } return content.toString(); } } </code></pre> <p>Now create a new Activity where you want to get the list of nearest places.</p> <p>/** * */</p> <pre><code> package com.android.code.GoogleMap.NearsetLandmark; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import android.app.AlertDialog; import android.app.ListActivity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.graphics.drawable.Drawable; import android.location.Address; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.android.code.R; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; /** * @author dwivedi ji * * */ public class CheckInActivity extends ListActivity { private String[] placeName; private String[] imageUrl; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); new GetPlaces(this,getListView()).execute(); } class GetPlaces extends AsyncTask&lt;Void, Void, Void&gt;{ Context context; private ListView listView; private ProgressDialog bar; public GetPlaces(Context context, ListView listView) { // TODO Auto-generated constructor stub this.context = context; this.listView = listView; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); bar.dismiss(); this.listView.setAdapter(new ArrayAdapter&lt;String&gt;(context, android.R.layout.simple_list_item_1, placeName)); } @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); bar = new ProgressDialog(context); bar.setIndeterminate(true); bar.setTitle("Loading"); bar.show(); } @Override protected Void doInBackground(Void... arg0) { // TODO Auto-generated method stub findNearLocation(); return null; } } public void findNearLocation() { PlacesService service = new PlacesService("past your key"); /* Hear you should call the method find nearst place near to central park new delhi then we pass the lat and lang of central park. hear you can be pass you current location lat and lang.The third argument is used to set the specific place if you pass the atm the it will return the list of nearest atm list. if you want to get the every thing then you should be pass "" only */ /* hear you should be pass the you current location latitude and langitude, */ List&lt;Place&gt; findPlaces = service.findPlaces(28.632808,77.218276,""); placeName = new String[findPlaces.size()]; imageUrl = new String[findPlaces.size()]; for (int i = 0; i &lt; findPlaces.size(); i++) { Place placeDetail = findPlaces.get(i); placeDetail.getIcon(); System.out.println( placeDetail.getName()); placeName[i] =placeDetail.getName(); imageUrl[i] =placeDetail.getIcon(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload