2017-01-22 5 views
7

पर मानचित्र ऑब्जेक्ट का उपयोग किये बिना बंद स्थानों की सूची मैं एक एंड्रॉइड एप्लिकेशन बना रहा हूं जिसे यह जांचने की आवश्यकता है कि उपयोगकर्ता ब्याज की जगह के करीब है या नहीं। सिनेमा घर। (1 किमी के भीतर)एंड्रॉइड

हालांकि मुझे उपयोगकर्ता को एक मानचित्र देखने की आवश्यकता नहीं है जो मुझे लगता है कि Google स्थानों api का उपयोग करने के लिए आवश्यक है। मैंने कुछ शोध किया है लेकिन मुझे यकीन नहीं है कि एंड्रॉइड पर इसे कैसे पूरा किया जाए। कोई सुझाव गूगल मैप्स से (टिप्पणी या प्रासंगिक लिंक सहित सराहना किया जाएगा)

+0

मैं करने के लिए की आवश्यकता होगी, याद नहीं है 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

+0

Google मानचित्र दिखाने के अलावा आप उपयोगकर्ता को कैसे उम्मीद कर रहे हैं यह डेटा दिखाओ? – Stallion

उत्तर

6

पास के साइटों को देखने के लिए,

1.- उपयोग Nearby Search Requests, link here

2.- उपयोग फोन निर्देशांक, एक पाने के लिए coords के पास फिल्म थियेटर की सूची ...

https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.503186,-0.126446&radius=5000&types=movie+theater&key=YOUR_API_KEY

3.- दो निर्देशांक तुलना करें और अपने जादू करते हैं, हो सकता है कि दो अंक और उपयोगकर्ता शो घ द्वारा दूरी मिलता है आईटेंस ..

नोट: यदि आप बहुत से विशेष स्थान चाहते हैं, तो आपको इसे करने का एक और तरीका देखना होगा। मैंने यही सोचा था ... है, आपके सर्वर में बहुत से निकटतम स्थानों, (संग्रहालय, मूवी थियेटर इत्यादि) के साथ कॉर्ड द्वारा अनुरोध करने की आवश्यकता है, और इसे सहेजने के लिए क्योंकि Google आपको पर सर्वर चेक करता है कई बार में, उपयोगकर्ता coordenates भेज जब आप निकटतम स्थानों की एक सूची, अगर नहीं, सबसे अच्छा pleaces के सूची देखें और अपने सर्वर में बचाने के लिए और उपयोगकर्ता के लिए भेज दिया जाएगा,

आप एक का उपयोग करने की आवश्यकता होगी कुछ गणना समन्वय, जैसे श्रेणी, यदि उपयोगकर्ता इस समन्वय के पास है कि मेरे पास डेटाबेस में जानकारी है, तो अगर निकटतम स्थानों से परामर्श करने के लिए सर्वर से अनुरोध करें (आपकी पूर्वनिर्धारित सूची के साथ)

मेरी अंग्रेजी के लिए खेद है। अधिक जानकारी के लिए

लिंक
Find Places Nearby in Google Maps using Google Places API–Android App
Places APIs and Related Products
how to display nearby places like atm,hospitals in android google map?

+0

यह अच्छी तरह से काम करना चाहिए। आप जीपीएस पर प्रसारण रिसीवर का उपयोग कर फोन स्थान प्राप्त कर सकते हैं, और वॉली अनुरोध को कास्ट करने और प्रतिक्रिया का विश्लेषण करने के लिए प्राप्त कर सकते हैं। – BMU

2

आप आस-पास के स्थानों के लिए जागरूकता एपीआई का भी उपयोग कर सकते हैं। तुम बस के रूप में

below-
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) 
       .addApi(Awareness.API) 
       .addConnectionCallbacks(this) 
       .build(); 

mGoogleApiClient.connect(); 

तो आसपास के स्थानों के लिए विधि नीचे कॉल GoogleApiClient वस्तु बनाना होगा।

private void detectNearbyPlaces() { 
     if (!checkLocationPermission()) { 
      return; 
     } 

     Awareness.SnapshotApi.getPlaces(mGoogleApiClient) 
       .setResultCallback(new ResultCallback<PlacesResult>() { 
        @Override 
        public void onResult(@NonNull PlacesResult placesResult) { 
         Place place; 
         if (placesResult.getPlaceLikelihoods() != null) { 
          for (PlaceLikelihood placeLikelihood : placesResult.getPlaceLikelihoods()) { 
           place = placeLikelihood.getPlace(); 
           Log.e(TAG, place.getName().toString() + "\n" + place.getAddress().toString()); 
           Log.e(TAG, "Rating: " + place.getRating()); 
           Log.e(TAG, "Likelihood that the user is here: " + placeLikelihood.getLikelihood() * 100 + "%"); 
          } 
         } 
        } 
       }); 
    } 

आशा है कि यह आपके लिए सहायक होगा।

3

इस स्थान प्राप्त करने का प्रयास करें, प्रवेश अपने स्वयं के खोज प्रश्न

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