इस स्थान प्राप्त करने का प्रयास करें, प्रवेश अपने स्वयं के खोज प्रश्न
searchString = getIntent().getStringExtra("search_key");
GetPlacesTask getPlacesTask = new GetPlacesTask();
String url = getResources().getString(R.string.near_by_search) +
"location="+latitude+","+longitude+"&radius=1000&type=" +
searchString +"&keyword="+ searchString +
"&key="+ YOUR_API_KEY;
String[] stringArray = new String[]{url};
getPlacesTask.execute(stringArray);
GetPlacesTask
private class GetPlacesTask extends AsyncTask<String, String, ArrayList<Place>>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected ArrayList<Place> doInBackground(String... strings)
{
try
{
URL url = new URL(strings[0]);
HttpHandler httpHandler = new HttpHandler(url);
String result = httpHandler.getURLResponse();
ArrayList<Place> placesArrayList = new ArrayList<>();
JSONObject mainResponse;
JSONArray jsonArray;
mainResponse = new JSONObject(jsonString);
jsonArray = mainResponse.getJSONArray("results");
if(jsonArray.length() > 0)
{
placesArrayList = fetch(jsonArray);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return placesArrayList;
}
@Override
protected void onPostExecute(ArrayList<Place> placesArrayList)
{
super.onPostExecute(placesArrayList);
if(!placesArrayList.isEmpty())
{
//Show Places in your views
}
}
}
HttpHandler वर्ग
public class HttpHandler
{
private URL url;
public HttpHandler(URL url)
{
this.url = url;
}
public String getURLResponse()
{
String response = "";
try
{
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
InputStream is = new BufferedInputStream(urlConnection.getInputStream());
response = convertStreamIntoString(is);
Log.d("RESPONSE", response);
}
catch (Exception e)
{
e.printStackTrace();
}
return response;
}
private String convertStreamIntoString(InputStream inputStream)
{
String response = "";
String line;
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line);
}
response = sb.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return response;
}
}
Here is the repository for the same
मैं करने के लिए की आवश्यकता होगी, याद नहीं है di परिणाम प्राप्त करने के लिए एक मानचित्र चलाएं ... https://developers.google.com/places/web-service/search परिणाम एक जेसन है, आप जो भी चाहते हैं वह कर सकते हैं। आस-पास के संग्रहालय के लिए उदाहरण https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.503186,-0.126446&radius=5000&type=museum&key=YOUR_API_KEY – Distwo
Google मानचित्र दिखाने के अलावा आप उपयोगकर्ता को कैसे उम्मीद कर रहे हैं यह डेटा दिखाओ? – Stallion