Android
Data objects
AndroidアプリでのParse GeoPointsの技術的実装ガイド
30 分
androidアプリでのparse geopointsの使用 はじめに parseを使用すると、オブジェクトに実世界の緯度と経度の座標を関連付けることができます。 parsegeopoint を parseuser に追加することで、他のユーザーに最も近いユーザーを簡単に見つけたり、アプリのユーザーの位置を表示したり、ユーザーの位置情報を保存したりすることができます。 また、任意の parseobject に parsegeopoint を関連付けることもできます。たとえば、アプリが物理的な提携店に関連している場合、これらの店舗の位置を表示するアクティビティを作成したり、ユーザーに最も近い店舗を示したりすることができます。この関連付けの使用例として、アプリがキャラクターを表すためにparseobjectsを作成したゲームであれば、これらのキャラクターにparsegeopointsを追加することで、プレイヤーの進行に沿って表示することができます。 このチュートリアルでは、back4appを通じてparsegeopointのいくつかの機能を使用する方法を説明します。 このチュートリアルに従った後、次のことができるようになります いつでも、このチュートリアルで構築された完全なandroidプロジェクトにアクセスできます。私たちの githubリポジトリ です。 前提条件 このチュートリアルを完了するには、以下が必要です: android studio back4appで作成されたユーザー登録 ログインアプリ。 注意: ユーザー登録 ログインアプリをback4appで作成する方法を学ぶには、ユーザー登録 ログインチュートリアルに従ってください。 android 4 0(アイスクリームサンドイッチ)以上を実行している実際のデバイス。 注意: このチュートリアルで構築されたアプリは、仮想デバイスでは期待通りに動作しない可能性が高く、仮想デバイスの現在の位置情報を取得できないため、クラッシュする可能性もあります。したがって、実際のデバイスを使用して実行することを強くお勧めします。 1 google apiキーの設定 parsegeopointに保存した位置を表示するには、地図を表示する必要があります。そのためには、google mapsアクティビティを使用するのが興味深いです。android studioでgoogle mapsアクティビティを作成するには、次の手順を実行します 「 ファイル ファイル 」に移動します > 新規 新規 > google google > google mapsアクティビティ google mapsアクティビティ すると、自動的に「 java java 」ファイル、「 layout layout 」ファイル、そして「 values values 」ファイルが作成されます。これらは、作成したgoogle mapsアクティビティに対応しています。 作成した values values ファイルに移動します(これは、「 app app > res res > values values > google maps api xml google maps api xml にアクセスすることで行えます)、下の画像に示すように。このファイルには、google maps apiキーを取得する方法に関するいくつかの指示が含まれています。基本的には、画像に示されたリンクを開く必要があります。 3\ 開いたら、googleアカウントにログインし、「 プロジェクトを作成 プロジェクトを作成 」オプションを選択し、「 続行 続行 」をクリックします。プロジェクトを作成している間に、googleがapiを有効にします。 4\ apiが有効になったら、apiキーを取得できるようになります。そのためには、クリックしてください。 5\ 次に、キーが作成され、コピーして「 値 値 」ファイルに貼り付けることができます。このページに導くファイルの「 ここにあなたのキー ここにあなたのキー 」と書かれている場所に。 6\ androidmanifest xmlファイルに以下の使用許可が必要です。上記の手順に従ってgoogleマップアクティビティを作成した場合、これらの権限のいずれかはすでにマニフェストに含まれているはずですが、アプリが正常に動作するためには両方とも必要ですので、androidmanifest xmlファイルに含まれているか確認し、そうでない場合は挿入してください。 1 \<uses permission android\ name="android permission access coarse location" /> 2 \<uses permission android\ name="android permission access fine location" /> 7\ あなたの mapsactivity mapsactivity , 次のものをインポートします 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 back4appダッシュボードを設定してユーザーの位置情報を保存する に行く back4appのウェブサイト にログインし、アプリを見つけてそのダッシュボードを開きます。 に行く コア コア > ブラウザ ブラウザ > ユーザー ユーザー , 下の画像に示されているように。 3\ さて、ユーザーの位置情報を保存するための新しい列を作成します。そのためには、右上の 編集 編集 ボタンをクリックします。下に示されているように。 4\ 次に、 列を追加 列を追加 をクリックします。 5\ 「どの種類のデータを保存しますか?」のフィールドで、geopointオプションを選択します。 6\ 「何と呼びますか?」のフィールドに、「 位置 」と入力します。 7\ それで、下の画像に示されているように、列を追加をクリックします。 8\ さて、あなたのアプリはユーザーの位置データを保存できるようになり、back4ppダッシュボードのユーザークラスは次のようになります 3 back4ppダッシュボードにユーザーの現在の位置を保存する 「 mapsactivity mapsactivity 」を開き、public class内で mapsactivity mapsactivity というintを定義します。名前は request location request location で、値は1、そして locationmanager locationmanager , 次のコードのようにします。 1 private static final int request location = 1; 2 locationmanager locationmanager; 2\ 「 oncreate oncreate 」メソッドで locationmanager locationmanager を作成します。次のコードのようにします。 1 locationmanager = (locationmanager)getsystemservice(context location service); 3\ ユーザーの位置情報をback4ppダッシュボードに保存するには、次のメソッドを実装し、 onmapready onmapready メソッド内で呼び出してください。 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\ 次のメソッドを実装することが非常に重要です。これにより、 savecurrentuserlocation savecurrentuserlocation メソッドが機能します。 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 ユーザーの位置情報を取得する ユーザーの位置情報を取得するには、現在のユーザーを特定し、その位置情報を保存し、次にback4appダッシュボードに保存された位置情報を返す必要があります。 そのためには、次のメソッドを実装し、必要に応じて呼び出してください。 mapsactivity mapsactivity で呼び出してください。 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 現在のユーザーの位置を地図に表示する ユーザーの位置を地図に表示するには、ユーザーの位置を取得し、取得した情報を使用して地図にマーカーを作成する必要があります。 そのためには、次のメソッドを実装し、 mapsactivity mapsactivity で呼び出します。 onmapready onmapready メソッドで。 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 現在のユーザーに最も近いユーザーを見つける 現在、空間座標が関連付けられたユーザーがたくさんいるので、どのユーザーが他のユーザーに最も近いかを見つけるのが良いでしょう。これはparsequeryを使用して行うことができます。まず、parseuserクエリを作成し、 wherenear wherenear , back4appのuserクラスのどの列でクエリを行っているかを指定します(この場合は「location」列)し、最も近いユーザーを見つけるための参照parsegeopointも指定します(この場合は現在のユーザーの位置に関連付けられたparsegeopoint)。次のコードがそれを行います 1 parsequery\<parseuser> query = parseuser getquery(); 2 query wherenear("location", getcurrentuserlocation()); 2\ このクエリの結果の数を制限するには、次の制限を追加します。 setlimit setlimit デフォルトでは、結果は100に制限されています。 wherenear wherenear 制限により、クエリはcurrentuserlocationからの距離(近い順から遠い順)で並べられたユーザーの配列を取得します。近くのユーザーを見つけるための制限を2に設定すると、クエリの結果リストには現在のユーザーと最も近いユーザーの2人だけが含まれます。次のコードは結果の制限を2に設定します 1 query setlimit(2); 3\ クエリを制限したので、結果を取得しましょう。そのためには、 findinbackground findinbackground メソッドを呼び出し、結果を格納するユーザーのリストと、エラーを処理するためのparseexceptionを引数として渡します。エラーを避けるために、クエリが実行された後にキャッシュされた結果をクリアすることを忘れないでください。次のコードはそれを行います 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\ エラーが発生しない場合、現在のユーザーに最も近い2人のユーザーがリストに表示されます(実際の現在のユーザーとそのユーザーから最も近いユーザー)。今、あなたは現在のユーザーでない人を見つけるだけです。それを行うために、 nearusers nearusers ブロック内で次のコードを使用します 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\ 現在のユーザーに最も近いユーザーが誰であるかがわかったので、次に、 distanceinkilometersto distanceinkilometersto メソッドを使用して、彼らの間の距離を測定できます。それを行うために、次のコードを使用します 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 "); 上記で使用されている alertdisplayer alertdisplayer メソッドは、以下の通りです 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\ 次のコードを使用して、地図上に両方のユーザーを表示することもできます 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)); 上記の6つのステップをすべて実行する完全なメソッドは次のとおりです。 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 back4appを設定してparsegeopointをparseobjectsに関連付ける あなたが構築している例のアプリが物理的な提携店のグループに関連付けられていると仮定します。この店舗のすべての物理的な提携店を地図に表示することは興味深いでしょう。そのためには、back4pp dashboardでstoresクラスを作成し、既存の店舗をparseobjectsとして保存し、その位置を記録します。その後、アプリは物理的な提携店をクエリし、地図上にその位置を表示できるようになります。以下の手順が役立ちます。 1 back4appのウェブサイト , にログインし、アプリを見つけてそのダッシュボードを開きます。 2\ コア コア > ブラウザ ブラウザ > クラスを作成 クラスを作成 , 下の画像のようにします。 3\ フィールド「どのタイプ のクラスが必要ですか? のクラスが必要ですか? , 「 カスタム カスタム オプションを選択します。 4\ フィールドで 何と呼ぶべきですか? 何と呼ぶべきですか? , タイプ「stores」と入力し、次に クラスを作成 クラスを作成 ボタンをクリックします。 5\ その後、「stores」と呼ばれる新しいクラスが表示され、2つのカラムを挿入する必要があります:データ型 文字列 文字列 と呼ばれるカラム 名前 名前 , さらにデータ型 geopoint geopoint と呼ばれる別のカラム 位置 位置 カラムの作成方法を忘れた場合は、ステップ2に戻り、back4appダッシュボードでカラムを作成する方法が説明されています。あなたのクラスはこのようになります 6\ では、このクラスに情報を入力します。そのためには、右上のメニューまたはページの中央にある 行を追加 行を追加 ボタンをクリックします。下の画像に示されています。 7\ 次に、必要な情報で行を埋めます:店舗の名前とその緯度と経度。いくつかのデータを挿入した後、あなたのstoresクラスは下の画像のようになります。さらにデータを挿入したい場合は、上部の 行を追加 行を追加 ボタンをクリックするか、 + + ボタンを最後のデータ行の下にクリックします。 今、あなたはアプリで店舗の位置情報を使用する準備が整いました。 8 地図上にすべての店舗の位置を表示する 1\ あなたがクラスに追加したすべての店舗を表示するには、 mapsactivity mapsactivity を使用して、parsequeryを使います。まず、クエリを行いたいback4pp dashboardクラスの名前(この場合は「stores」クラス)を指定して、parseobjectクエリを作成する必要があります。そして、 whereexists whereexists , back4appのstoreクラスのクエリを行う列(この場合は「location」列)を指定します。以下のコードがそれを行います 1 parsequery\<parseobject> query = parsequery getquery("stores"); 2 query whereexists("location"); 2\ クエリを制限したので、結果を取得しましょう。それを行うために、 findinbackground findinbackground メソッドを呼び出し、結果を格納する店舗のリストと、エラーを処理するためのparseexceptionを引数として渡します。 whereexists whereexists 制限により、位置を示すparsegeopointが関連付けられたクラスのparseobjectsのみが店舗のリストに格納されます。エラーを避けるために、クエリが実行された後にキャッシュされた結果をクリアすることを忘れないでください。以下のコードがそれを行います 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\ エラーが発生しない場合、 stores stores リストには位置が関連付けられたすべての店舗が含まれます。今、地図に表示するためにループを作成するだけです。そのためには、 if (e == null) if (e == null) ブロック内で以下のコードを使用します。 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 } 上記の3つのステップをすべて実行する完全なメソッドは以下の通りです。これを onmapready onmapready メソッドで呼び出すと機能します。 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 店舗に最も近いユーザーを表示する 1\ 空間座標が関連付けられた店舗がいくつかあるので、どの店舗がユーザーに最も近いかを見つけるのが良いでしょう。これはparsequeryを使用して行うことができます。まず、クエリを作成し、クエリしたいback4pp dashboardクラスの名前(この場合は「stores」クラス)を指定し、 wherenear wherenear , back4appのstoreクラスのクエリを行う列(この場合は「location」列)を指定します。以下のコードがそれを行います 1 parsequery\<parseobject> query = parsequery getquery("stores"); 2 query wherenear("location", getcurrentuserlocation()); 2\ このクエリの結果の数を制限するには、 setlimit setlimit 制限を追加します。デフォルトでは、結果は100に制限されています。 wherenear wherenear 制限により、クエリは現在のユーザーの位置からの距離(最も近いものから最も遠いもの)で順序付けられたユーザーの配列を取得します。近くのユーザーを見つけるための制限を1に設定すると、クエリの結果リストには1つの店舗のみが含まれます:現在のユーザーに最も近い店舗です。以下のコードは、結果の制限を1に設定します 1 query setlimit(1); 3\ クエリを制限したので、結果を取得しましょう。そのためには、 findinbackground findinbackground メソッドを呼び出し、結果が格納されるストアオブジェクトのリストと、エラーを処理するためのparseexceptionを引数として渡します。エラーを避けるために、クエリが結果を見つけた後はキャッシュされた結果をクリアすることを忘れないでください。以下のコードはそれを行います 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\ エラーが発生しなければ、 nearstores nearstores リストには現在のユーザーに最も近いストアが含まれます。これを mapsactivity mapsactivity に表示するだけです。そのためには、 if (e == null) if (e == null) ブロック内で以下のコードを使用します 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)); 上記で使用されている alertdisplayer alertdisplayer メソッドは、ステップ6(現在のユーザーに最も近いユーザーを見つける)と同じです。 上記の4つのステップをすべて実行する完全なメソッドは次のとおりです 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 アプリをテストする 1\ back4appのウェブサイト https //www back4app com/ にログインします。 2\ アプリを見つけて、 ダッシュボード ダッシュボード > コア コア > ブラウザ ブラウザ > ユーザー ユーザー を作成し、位置情報を関連付けて、メソッド showclosestuser showclosestuser が機能するようにします。 3\ 実際のデバイスでアプリを実行し、アカウントにサインアップします。すべての機能を試してみてください! 4\ back4appのダッシュボードに戻り、ユーザー行に位置情報が保存されているか確認します。 完了しました! この段階で、back4appを通じてparsegeopointのいくつかの機能を使用できます!