Android
Data objects
Parse GeoPoints su Android per sviluppatori di software
34 min
utilizzare parse geopoints nella tua app android introduzione parse ti consente di associare coordinate di latitudine e longitudine del mondo reale a un oggetto aggiungendo un parsegeopoint a un parseuser , sarai in grado di scoprire facilmente quale utente è più vicino a un altro, mostrare le posizioni degli utenti della tua app e anche memorizzare le informazioni sulla posizione dell'utente, tra le altre possibilità puoi anche associare un parsegeopoint a qualsiasi parseobject ad esempio, se la tua app è associata a un negozio con affiliati fisici, sarai in grado di creare un'attività per mostrare la posizione di quei negozi o per mostrare all'utente quale negozio è più vicino a lui un altro esempio di utilizzo di questa associazione se la tua app è un gioco in cui hai creato parseobjects per rappresentare personaggi, aggiungere parsegeopoints a questi personaggi permetterebbe loro di essere mostrati lungo il percorso del giocatore questo tutorial spiega come utilizzare alcune funzionalità di parsegeopoint tramite back4app dopo aver seguito questo tutorial, sarai in grado di fare questo in qualsiasi momento, puoi accedere al progetto android completo costruito con questo tutorial nel nostro repository github requisiti per completare questo tutorial, abbiamo bisogno di android studio un'app di registrazione utente login creata su back4app nota segui il tutorial di registrazione utente login per imparare a creare un'app di registrazione utente login su back4app un dispositivo reale che esegue android 4 0 (ice cream sandwich) o versioni successive nota è molto probabile che l'app costruita con questo tutorial non funzioni come previsto su un dispositivo virtuale e potrebbe anche bloccarsi perché potrebbe non recuperare la posizione attuale del dispositivo virtuale quindi ti consigliamo vivamente di utilizzare un dispositivo reale per eseguirla 1 configura la chiave api di google per mostrare la posizione che hai memorizzato in un parsegeopoint, dovrai visualizzare una mappa per fare ciò, è interessante utilizzare un'attività google maps per creare un'attività google maps in android studio, segui questi passaggi vai a file file > nuovo nuovo > google google > attività google maps attività google maps poi, automaticamente, verrà creato un file java file java , un file layout file layout e un file values file values corrispondente all'attività google maps che hai creato vai al file creato values values (puoi farlo accedendo a app app > res res > values values > google maps api xml google maps api xml ), come mostrato nell'immagine qui sotto questo file ti darà alcune istruzioni su come ottenere una chiave api di google maps fondamentalmente, dovresti aprire il link mostrato nell'immagine 3\ dopo averlo aperto, dovresti accedere al tuo account google, selezionare l' crea un progetto crea un progetto opzione e cliccare su continua continua durante la creazione del progetto, google abiliterà la tua api 4\ dopo che la tua api è stata abilitata, sarai in grado di ottenere una chiave api, per farlo clicca su 5\ poi, la tua chiave verrà creata e potrai copiarla e incollarla nel file dei valori file dei valori che ti ha portato a questa pagina, nel posto dove è scritto la tua chiave qui la tua chiave qui 6\ è importante avere i permessi di utilizzo qui sotto nel tuo file androidmanifest xml se hai creato l'activity di google maps seguendo le istruzioni sopra, allora uno di questi permessi dovrebbe già essere nel tuo manifest, comunque, avrai bisogno di entrambi per far funzionare correttamente la tua app, quindi controlla se sono nel tuo file androidmanifest xml, altrimenti, inseriscili 1 \<uses permission android\ name="android permission access coarse location" /> 2 \<uses permission android\ name="android permission access fine location" /> 7\ all'inizio del tuo mapsactivity mapsactivity , importa il seguente 1 // android dependencies 2 import android manifest; 3 import android app progressdialog; 4 import android content context; 5 import android content dialoginterface; 6 import android content intent; 7 import android content pm packagemanager; 8 import android location location; 9 import android location locationmanager; 10 import android support annotation nonnull; 11 import android support v4 app activitycompat; 12 import android support v4 app fragmentactivity; 13 import android os bundle; 14 import android util log; 15 import android view\ view; 16 import android widget button; 17 // google maps dependencies 18 import com google android gms maps cameraupdatefactory; 19 import com google android gms maps googlemap; 20 import com google android gms maps onmapreadycallback; 21 import com google android gms maps supportmapfragment; 22 import com google android gms maps model bitmapdescriptorfactory; 23 import com google android gms maps model latlng; 24 import com google android gms maps model markeroptions; 25 // parse dependencies 26 import com parse findcallback; 27 import com parse parseexception; 28 import com parse parsegeopoint; 29 import com parse parsequery; 30 import com parse parseuser; 31 // java dependencies 32 import java util list; 2 configura il dashboard di back4app per salvare la posizione dell'utente vai a sito web di back4app accesso, trova la tua app e apri il suo dashboard vai a core core > browser browser > user user , come mostrato nell'immagine qui sotto 3\ ora, crea una nuova colonna per salvare la posizione dell'utente per farlo, fai clic sul modifica modifica pulsante in alto a destra, come mostrato qui sotto 4\ quindi, fai clic su aggiungi una colonna aggiungi una colonna 5\ nel campo che tipo di dati vuoi memorizzare?, scegli l'opzione geopoint 6\ nel campo come lo chiamiamo?, digita “ posizione ” 7\ quindi, fai clic su aggiungi colonna, come mostrato nell'immagine qui sotto 8\ ora, la tua app è in grado di memorizzare i dati sulla posizione degli utenti e la tua classe utente nel tuo dashboard back4pp dovrebbe apparire così 3 salva la posizione attuale degli utenti nel tuo dashboard back4pp apri il tuo mapsactivity mapsactivity e all'interno della classe pubblica mapsactivity mapsactivity definisci un int chiamato request location request location con valore 1 e un locationmanager locationmanager , come nel seguente codice 1 private static final int request location = 1; 2 locationmanager locationmanager; 2\ nel oncreate oncreate metodo crea il locationmanager locationmanager , come nel seguente codice 1 locationmanager = (locationmanager)getsystemservice(context location service); 3\ per salvare la posizione dell'utente nel tuo back4pp dashboard, implementa semplicemente il seguente metodo e chiamalo nel tuo onmapready onmapready metodo 1 private void savecurrentuserlocation() { 2 // requesting permission to get user's location 3 if(activitycompat checkselfpermission(usersactivity this, manifest permission access fine location) != packagemanager permission granted && activitycompat checkselfpermission(usersactivity this, manifest permission access coarse location) != packagemanager permission granted){ 4 activitycompat requestpermissions(usersactivity this, new string\[]{android manifest permission access fine location}, request location); 5 } 6 else { 7 // getting last know user's location 8 location location = locationmanager getlastknownlocation(locationmanager network provider); 9 10 // checking if the location is null 11 if(location != null){ 12 // if it isn't, save it to back4app dashboard 13 parsegeopoint currentuserlocation = new parsegeopoint(location getlatitude(), location getlongitude()); 14 15 parseuser currentuser = parseuser getcurrentuser(); 16 17 if (currentuser != null) { 18 currentuser put("location", currentuserlocation); 19 currentuser saveinbackground(); 20 } else { 21 // do something like coming back to the login activity 22 } 23 } 24 else { 25 // if it is null, do something like displaying error and coming back to the menu activity 26 } 27 } 28 } 4\ è davvero importante implementare il seguente metodo per far funzionare il savecurrentuserlocation savecurrentuserlocation metodo 1 @override 2 public void onrequestpermissionsresult(int requestcode, @nonnull string\[] permissions, @nonnull int\[] grantresults){ 3 super onrequestpermissionsresult(requestcode, permissions, grantresults); 4 5 switch (requestcode){ 6 case request location 7 savecurrentuserlocation(); 8 break; 9 } 10 } 4 recupera la posizione dell'utente per recuperare la posizione dell'utente, dovrai trovare chi è l'utente attuale, salvare la sua posizione e poi restituire la posizione salvata nel tuo back4app dashboard per fare ciò, implementa il seguente metodo nel tuo mapsactivity mapsactivity e chiamalo quando necessario 1 / saving the current user location, using the savecurrentuserlocation method of step 3, to avoid 2 null pointer exception and also to return the user's most current location / 3 savecurrentuserlocation(); 4 private parsegeopoint getcurrentuserlocation(){ 5 6 // finding currentuser 7 parseuser currentuser = parseuser getcurrentuser(); 8 9 if (currentuser == null) { 10 // if it's not possible to find the user, do something like returning to login activity 11 } 12 // otherwise, return the current user location 13 return currentuser getparsegeopoint("location"); 14 15 } 5 mostrare la posizione attuale dell'utente sulla mappa per visualizzare la posizione dell'utente sulla mappa, è necessario recuperare la posizione dell'utente e poi creare un marcatore sulla mappa utilizzando le informazioni recuperate per fare ciò, implementa il seguente metodo nella tua mapsactivity mapsactivity e chiamalo nel onmapready onmapready metodo 1 private void showcurrentuserinmap(final googlemap googlemap){ 2 3 // calling retrieve user's location method of step 4 4 parsegeopoint currentuserlocation = getcurrentuserlocation(); 5 6 // creating a marker in the map showing the current user location 7 latlng currentuser = new latlng(currentuserlocation getlatitude(), currentuserlocation getlongitude()); 8 googlemap addmarker(new markeroptions() position(currentuser) title(parseuser getcurrentuser() getusername()) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue red))); 9 10 // zoom the map to the currentuserlocation 11 googlemap animatecamera(cameraupdatefactory newlatlngzoom(currentuser, 5)); 12 } 6 trovare l'utente più vicino a quello attuale ora che hai un gruppo di utenti con coordinate spaziali associate, sarebbe utile scoprire quale utente è più vicino a un altro questo può essere fatto utilizzando un parsequery prima, dovrai creare una query parseuser e restringerla con wherenear wherenear , informando in quale colonna della classe user su back4app stai effettuando la query (in questo caso la colonna “location”) e anche informare il riferimento parsegeopoint per la query da cui sarà trovato l'utente più vicino (in questo caso il parsegeopoint associato alla posizione attuale dell'utente) il seguente codice fa questo 1 parsequery\<parseuser> query = parseuser getquery(); 2 query wherenear("location", getcurrentuserlocation()); 2\ puoi limitare il numero di risultati di questa query aggiungendo ad essa la restrizione setlimit setlimit per impostazione predefinita, i risultati sono limitati a 100 poiché la wherenear wherenear restrizione farà sì che la query recuperi un array di utenti ordinati per distanza (dal più vicino al più lontano) dalla posizione dell'utente attuale, impostando il limite degli utenti vicini da trovare a 2, la lista dei risultati della query avrà solo due utenti l'utente attuale e l'utente più vicino a lui il seguente codice imposta il limite dei risultati a 2 1 query setlimit(2); 3\ ora che hai ristretto la tua query, recuperiamo i suoi risultati per fare ciò, chiamerai un findinbackground findinbackground metodo e passerai come argomento una lista di utenti, in cui verranno memorizzati i risultati della query e anche un parseexception per gestire gli errori per evitare errori, non dimenticare di cancellare i risultati memorizzati nella cache dopo l'esecuzione della query il seguente codice lo fa 1 query findinbackground(new findcallback\<parseuser>() { 2 @override public void done(list\<parseuser> nearusers, parseexception e) { 3 if (e == null) { 4 // do something with the list of results of your query 5 } else { 6 // handle the error 7 } 8 } 9 }); 10 parsequery clearallcachedresults(); 11 } 4\ se non si verifica alcun errore, avrai nella nearusers nearusers elenco i due utenti più vicini all'utente attuale (l'utente attuale e l'utente più vicino a lui), ora dovrai solo trovare chi non è l'utente attuale per fare ciò, all'interno del if (e == null) if (e == null) blocco usa il seguente codice 1 // avoiding null pointer 2 parseuser closestuser = parseuser getcurrentuser(); 3 // set the closestuser to the one that isn't the current user 4 for(int i = 0; i < nearusers size(); i++) { 5 if(!nearusers get(i) getobjectid() equals(parseuser getcurrentuser() getobjectid())) { 6 closestuser = nearusers get(i); 7 } 8 } 5\ ora che sai chi è l'utente più vicino a quello attuale, puoi misurare la distanza tra di loro usando il distanceinkilometersto distanceinkilometersto metodo per fare ciò, usa il seguente codice 1 // finding and displaying the distance between the current user and the closest user to him 2 double distance = getcurrentuserlocation() distanceinkilometersto(closestuser getparsegeopoint("location")); 3 alertdisplayer("we found the closest user from you!", "it's " + closestuser getusername() + " \nyou are " + math round (distance 100 0) / 100 0 + " km from this user "); il alertdisplayer alertdisplayer metodo utilizzato sopra è il seguente 1 private void alertdisplayer(string title,string message){ 2 android app alertdialog builder builder = new android app alertdialog builder(usersactivity this) 3 settitle(title) 4 setmessage(message) 5 setpositivebutton("ok", new dialoginterface onclicklistener() { 6 @override 7 public void onclick(dialoginterface dialog, int which) { 8 dialog cancel(); 9 } 10 }); 11 android app alertdialog ok = builder create(); 12 ok show(); 13 } 6\ puoi anche mostrare entrambi gli utenti sulla mappa, utilizzando il seguente codice 1 // showing current user in map, using the method implemented in step 5 2 showcurrentuserinmap(mmap); 3 // creating a marker in the map showing the closest user to the current user location, using method implemented in step 4 4 latlng closestuserlocation = new latlng(closestuser getparsegeopoint("location") getlatitude(), closestuser getparsegeopoint("location") getlongitude()); 5 googlemap addmarker(new markeroptions() position(closestuserlocation) title(closestuser getusername()) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue green))); 6 // zoom the map to the currentuserlocation 7 googlemap animatecamera(cameraupdatefactory newlatlngzoom(closestuserlocation, 3)); il metodo completo che esegue tutti i 6 passaggi sopra è il seguente 1 private void showclosestuser(final googlemap googlemap){ 2 parsequery\<parseuser> query = parseuser getquery(); 3 query wherenear("location", getcurrentuserlocation()); 4 // setting the limit of near users to find to 2, you'll have in the nearusers list only two users the current user and the closest user from the current 5 query setlimit(2); 6 query findinbackground(new findcallback\<parseuser>() { 7 @override public void done(list\<parseuser> nearusers, parseexception e) { 8 if (e == null) { 9 // avoiding null pointer 10 parseuser closestuser = parseuser getcurrentuser(); 11 // set the closestuser to the one that isn't the current user 12 for(int i = 0; i < nearusers size(); i++) { 13 if(!nearusers get(i) getobjectid() equals(parseuser getcurrentuser() getobjectid())) { 14 closestuser = nearusers get(i); 15 } 16 } 17 // finding and displaying the distance between the current user and the closest user to him, using method implemented in step 4 18 double distance = getcurrentuserlocation() distanceinkilometersto(closestuser getparsegeopoint("location")); 19 alertdisplayer("we found the closest user from you!", "it's " + closestuser getusername() + " \n you are " + math round (distance 100 0) / 100 0 + " km from this user "); 20 // showing current user in map, using the method implemented in step 5 21 showcurrentuserinmap(mmap); 22 // creating a marker in the map showing the closest user to the current user location 23 latlng closestuserlocation = new latlng(closestuser getparsegeopoint("location") getlatitude(), closestuser getparsegeopoint("location") getlongitude()); 24 googlemap addmarker(new markeroptions() position(closestuserlocation) title(closestuser getusername()) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue green))); 25 // zoom the map to the currentuserlocation 26 googlemap animatecamera(cameraupdatefactory newlatlngzoom(closestuserlocation, 3)); 27 } else { 28 log d("store", "error " + e getmessage()); 29 } 30 } 31 }); 32 parsequery clearallcachedresults(); 33 } 7 configura back4app per associare parsegeopoint a parseobjects supponiamo che l'app di esempio che stai costruendo sia associata a un gruppo di negozi con affiliati fisici sarebbe interessante mostrare tutti gli affiliati fisici di questo negozio sulla mappa per fare ciò, crea una classe stores nel dashboard di back4pp, salva i negozi esistenti come parseobjects, le loro posizioni e dopo che l'app sarà in grado di interrogare gli affiliati fisici e visualizzare le loro posizioni sulla mappa i seguenti passaggi ti aiuteranno in questo 1 vai a sito web di back4app , accedi, trova la tua app e apri il suo dashboard 2\ vai a core core > browser browser > crea una classe crea una classe , come mostrato nell'immagine qui sotto 3\ nel campo che tipo o di classe hai bisogno? o di classe hai bisogno? , scegli l'opzione personalizzata personalizzata 4\ nel campo come dovremmo chiamarlo? come dovremmo chiamarlo? , digita “stores” e poi clicca sul crea classe crea classe pulsante 5\ poi verrà mostrata una nuova classe chiamata “stores” e dovresti inserire 2 colonne una colonna con tipo di dato stringa stringa chiamata nome nome , così come un'altra colonna con tipo di dato geopoint geopoint chiamata posizione posizione se non ricordi come creare una colonna, torna al passo 2, lì è spiegato come creare una colonna nel back4app dashboard la tua classe dovrebbe finire così 6\ ora, riempi questa classe con informazioni per farlo, clicca sul aggiungi una riga aggiungi una riga pulsante nel menu in alto a destra o nel mezzo della pagina, come mostrato nell'immagine qui sotto 7\ poi riempi la riga con le informazioni richieste il nome del negozio e la sua latitudine e longitudine dopo aver inserito alcuni dati, la tua classe negozi dovrebbe apparire come nell'immagine qui sotto se vuoi inserire più dati, puoi cliccare sul aggiungi una riga aggiungi una riga pulsante in alto, o nel + + pulsante sotto l'ultima riga di dati ora sei pronto per utilizzare le informazioni sulla posizione dei negozi nella tua app 8 mostra tutte le posizioni dei negozi sulla mappa 1\ puoi mostrare tutti i negozi che hai aggiunto alla tua classe su mapsactivity mapsactivity utilizzando un parsequery prima, dovrai creare una query parseobject, informando il nome della classe back4pp dashboard che desideri interrogare (in questo caso la classe “stores”), e restringerla con whereexists whereexists , informando la colonna della classe store su back4app su cui stai eseguendo la query (in questo caso la colonna “location”) il seguente codice fa questo 1 parsequery\<parseobject> query = parsequery getquery("stores"); 2 query whereexists("location"); 2\ ora che hai ristretto la tua query, recuperiamo i suoi risultati per fare ciò, chiamerai un findinbackground findinbackground metodo e passerai come argomento una lista di negozi, in cui verranno memorizzati i risultati della query e anche un parseexception per gestire gli errori la whereexists whereexists restrizione farà sì che solo i parseobjects della classe che hanno un parsegeopoint associato a loro che indica la loro posizione vengano memorizzati nella lista dei negozi per evitare errori, non dimenticare di cancellare i risultati memorizzati nella cache dopo l'esecuzione della query il seguente codice fa questo 1 query findinbackground(new findcallback\<parseobject>() { 2 @override public void done(list\<parseobject> stores, parseexception e) { 3 if (e == null) { 4 // do something with the list of results of your query 5 } else { 6 // handle the error 7 } 8 } 9 }); 10 parsequery clearallcachedresults(); 11 } 3\ se non si verifica alcun errore, avrai nella stores stores lista tutti i negozi con posizione associata, ora dovrai solo fare un ciclo per visualizzarli sulla mappa per fare ciò, all'interno del if (e == null) if (e == null) blocco usa il seguente codice 1 for(int i = 0; i < stores size(); i++) { 2 latlng storelocation = new latlng(stores get(i) getparsegeopoint("location") getlatitude(), stores get(i) getparsegeopoint("location") getlongitude()); 3 googlemap addmarker(new markeroptions() position(storelocation) title(stores get(i) getstring("name")) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue azure))); 4 } il metodo completo che esegue tutti e 3 i passaggi sopra è qui sotto chiamalo nel onmapready onmapready metodo affinché funzioni 1 private void showstoresinmap(final googlemap googlemap){ 2 3 parsequery\<parseobject> query = parsequery getquery("stores"); 4 query whereexists("location"); 5 query findinbackground(new findcallback\<parseobject>() { 6 @override public void done(list\<parseobject> stores, parseexception e) { 7 if (e == null) { 8 for(int i = 0; i < stores size(); i++) { 9 latlng storelocation = new latlng(stores get(i) getparsegeopoint("location") getlatitude(), stores get(i) getparsegeopoint("location") getlongitude()); 10 googlemap addmarker(new markeroptions() position(storelocation) title(stores get(i) getstring("name")) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue azure))); 11 } 12 } else { 13 // handle the error 14 log d("store", "error " + e getmessage()); 15 } 16 } 17 }); 18 parsequery clearallcachedresults(); 19 } 9 mostra l'utente più vicino a un negozio 1\ ora che hai un insieme di negozi con coordinate spaziali associate, sarebbe utile scoprire quale negozio è più vicino a un utente questo può essere fatto utilizzando un parsequery prima, dovrai creare una query parseobject, informando il nome della classe back4pp dashboard che desideri interrogare (in questo caso la classe “stores”), e restringerla con wherenear wherenear , informando la colonna della classe store su back4app su cui stai eseguendo la query (in questo caso la colonna “location”) il seguente codice lo fa 1 parsequery\<parseobject> query = parsequery getquery("stores"); 2 query wherenear("location", getcurrentuserlocation()); 2\ puoi limitare il numero di risultati di questa query aggiungendo ad essa la restrizione setlimit setlimit per impostazione predefinita, i risultati sono limitati a 100 poiché la wherenear wherenear restrizione farà sì che la query recuperi un array di utenti ordinati per distanza (dal più vicino al più lontano) dalla currentuserlocation, impostando il limite degli utenti vicini da trovare a 1, l'elenco dei risultati della query avrà solo un negozio il più vicino all'utente attuale il seguente codice imposta il limite dei risultati a 1 1 query setlimit(1); 3\ ora che hai ristretto la tua query, recuperiamo i suoi risultati per fare ciò, chiamerai un findinbackground findinbackground metodo e passerai come argomento una lista di oggetti store, in cui verranno memorizzati i risultati della query e anche un parseexception per gestire gli errori per evitare errori, non dimenticare di cancellare i risultati memorizzati nella cache dopo che la query ha trovato un risultato il seguente codice fa questo 1 query findinbackground(new findcallback\<parseobject>() { 2 @override public void done(list\<parseobject> nearstores, parseexception e) { 3 if (e == null) { 4 // do something with the list of results of your query 5 } else { 6 // handle the error 7 } 8 } 9 }); 10 parsequery clearallcachedresults(); 11 } 4\ se non si verifica alcun errore, avrai nella nearstores nearstores lista il negozio più vicino all'utente attuale, ora dovrai solo visualizzarlo su mapsactivity mapsactivity per fare ciò, all'interno del if (e == null) if (e == null) blocco usa il seguente codice 1 parseobject closeststore = nearstores get(0); 2 // showing current user location, using the method implemented in step 5 3 showcurrentuserinmap(mmap); 4 // finding and displaying the distance between the current user and the closest store to him, using method implemented in step 4 5 double distance = getcurrentuserlocation() distanceinkilometersto(closeststore getparsegeopoint("location")); 6 alertdisplayer("we found the closest store from you!", "it's " + closeststore getstring("name") + " \n you are " + math round (distance 100 0) / 100 0 + " km from this store "); 7 // creating a marker in the map showing the closest store to the current user 8 latlng closeststorelocation = new latlng(closeststore getparsegeopoint("location") getlatitude(), closeststore getparsegeopoint("location") getlongitude()); 9 googlemap addmarker(new markeroptions() position(closeststorelocation) title(closeststore getstring("name")) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue green))); 10 // zoom the map to the closeststorelocation 11 googlemap animatecamera(cameraupdatefactory newlatlngzoom(closeststorelocation, 3)); il alertdisplayer alertdisplayer metodo utilizzato sopra è lo stesso del passo 6 (trovare l'utente più vicino a quello attuale) il metodo completo che esegue tutti e 4 i passaggi sopra è il seguente 1 private void showcloseststore(final googlemap googlemap){ 2 parsequery\<parseobject> query = parsequery getquery("stores"); 3 query wherenear("location", getcurrentuserlocation()); 4 // setting the limit of near stores to 1, you'll have in the nearstores list only one object the closest store from the current user 5 query setlimit(1); 6 query findinbackground(new findcallback\<parseobject>() { 7 @override public void done(list\<parseobject> nearstores, parseexception e) { 8 if (e == null) { 9 parseobject closeststore = nearstores get(0); 10 // showing current user location, using the method implemented in step 5 11 showcurrentuserinmap(mmap); 12 // finding and displaying the distance between the current user and the closest store to him, using method implemented in step 4 13 double distance = getcurrentuserlocation() distanceinkilometersto(closeststore getparsegeopoint("location")); 14 alertdisplayer("we found the closest store from you!", "it's " + closeststore getstring("name") + " \nyou are " + math round (distance 100 0) / 100 0 + " km from this store "); 15 // creating a marker in the map showing the closest store to the current user 16 latlng closeststorelocation = new latlng(closeststore getparsegeopoint("location") getlatitude(), closeststore getparsegeopoint("location") getlongitude()); 17 googlemap addmarker(new markeroptions() position(closeststorelocation) title(closeststore getstring("name")) icon(bitmapdescriptorfactory defaultmarker(bitmapdescriptorfactory hue green))); 18 // zoom the map to the closeststorelocation 19 googlemap animatecamera(cameraupdatefactory newlatlngzoom(closeststorelocation, 3)); 20 } else { 21 log d("store", "error " + e getmessage()); 22 } 23 } 24 }); 25 26 parsequery clearallcachedresults(); 27 28 } 10 testa la tua app 1\ accedi a sito web di back4app https //www back4app com/ 2\ trova la tua app e clicca su dashboard dashboard > core core > browser browser > utente utente e crea alcuni utenti con una posizione associata a loro per consentire al metodo showclosestuser showclosestuser di funzionare 3\ esegui la tua app su un dispositivo reale e registrati per un account prova ogni funzionalità! 4\ torna al dashboard di back4pp e verifica se la tua posizione è memorizzata nella riga del tuo utente è fatto! a questo punto, puoi utilizzare alcune funzionalità di parsegeopoint tramite back4app!