-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added service for reverse geocoding api integration
- Loading branch information
Showing
11 changed files
with
231 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/kathmandulivinglabs/osmnavigationapp/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kathmandulivinglabs.osmnavigationapp; | ||
|
||
public interface Constants { | ||
String TAG = "minion"; | ||
int REVERSE_GEO_CODE_RADIUS = 2; | ||
String TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJpY2hjaGhhIiwiZXhwIjoxNTgzMzgyOTM0LCJpYXQiOjE1ODE2NTQ5MzR9.MR0K8MBvoWWxvTIoaOJS3fwYyTkghEalv5yRVCrGh_4"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/models/Centroid.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/models/Geocode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.kathmandulivinglabs.navigationlibrary.models; | ||
|
||
public class Geocode { | ||
public double lat,lon; | ||
|
||
public Geocode(double lat, double lon) { | ||
this.lat = lat; | ||
this.lon = lon; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...main/java/com/kathmandulivinglabs/navigationlibrary/responses/ReverseGeoCodeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.kathmandulivinglabs.navigationlibrary.responses; | ||
|
||
public class ReverseGeoCodeResponse { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...n/java/com/kathmandulivinglabs/navigationlibrary/services/BaatoReverseGeoCodeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.kathmandulivinglabs.navigationlibrary.services; | ||
|
||
import android.content.Context; | ||
import android.location.Geocoder; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.kathmandulivinglabs.navigationlibrary.application.App; | ||
import com.kathmandulivinglabs.navigationlibrary.models.Geocode; | ||
import com.kathmandulivinglabs.navigationlibrary.models.Geometry; | ||
import com.kathmandulivinglabs.navigationlibrary.models.Place; | ||
import com.kathmandulivinglabs.navigationlibrary.requests.QueryAPI; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class BaatoReverseGeoCodeService { | ||
private Context context; | ||
private BaatoReverseGeoCodeRequestListener baatoSearchRequestListener; | ||
private String accessToken; | ||
private int radius; | ||
private Geocode geocode; | ||
|
||
public interface BaatoReverseGeoCodeRequestListener { | ||
/** | ||
* onSuccess method called after it is successful | ||
* onFailed method called if it can't places | ||
*/ | ||
void onSuccess(List<Place> places); | ||
|
||
void onFailed(Throwable error); | ||
} | ||
|
||
public BaatoReverseGeoCodeService(Context context) { | ||
this.context = context; | ||
} | ||
|
||
/** | ||
* Set the accessToken. | ||
*/ | ||
public BaatoReverseGeoCodeService setAccessToken(@NonNull String accessToken) { | ||
this.accessToken = accessToken; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the query to search. | ||
*/ | ||
public BaatoReverseGeoCodeService setGeoCode(@NonNull Geocode geoCode) { | ||
this.geocode = geoCode; | ||
return this; | ||
} | ||
|
||
public BaatoReverseGeoCodeService setRadius(@NonNull int radius) { | ||
this.radius = radius; | ||
return this; | ||
} | ||
|
||
/** | ||
* Method to set the UpdateListener for the AppUpdaterUtils actions | ||
* | ||
* @param baatoSearchRequestListener the listener to be notified | ||
* @return this | ||
*/ | ||
public BaatoReverseGeoCodeService withListener(BaatoReverseGeoCodeRequestListener baatoSearchRequestListener) { | ||
this.baatoSearchRequestListener = baatoSearchRequestListener; | ||
return this; | ||
} | ||
|
||
public void doReverseGeoCode() { | ||
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class); | ||
queryAPI.performReverseGeoCode(geocode.lat, geocode.lon, radius).enqueue(new Callback<List<Place>>() { | ||
@Override | ||
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) { | ||
if (response.isSuccessful() && response.body() != null) | ||
baatoSearchRequestListener.onSuccess(response.body()); | ||
else { | ||
try { | ||
baatoSearchRequestListener.onFailed(new Throwable(response.errorBody().string())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<List<Place>> call, Throwable throwable) { | ||
baatoSearchRequestListener.onFailed(throwable); | ||
} | ||
}); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
.../src/main/java/com/kathmandulivinglabs/navigationlibrary/services/BaatoSearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.kathmandulivinglabs.navigationlibrary.services; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.kathmandulivinglabs.navigationlibrary.application.App; | ||
import com.kathmandulivinglabs.navigationlibrary.models.Place; | ||
import com.kathmandulivinglabs.navigationlibrary.requests.QueryAPI; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class BaatoSearchService { | ||
private Context context; | ||
private BaatoSearchRequestListener baatoSearchRequestListener; | ||
private String accessToken, query; | ||
|
||
public interface BaatoSearchRequestListener { | ||
/** | ||
* onSuccess method called after it is successful | ||
* onFailed method called if it can't places | ||
*/ | ||
void onSuccess(List<Place> places); | ||
|
||
void onFailed(Throwable error); | ||
} | ||
|
||
public BaatoSearchService(Context context) { | ||
this.context = context; | ||
} | ||
|
||
/** | ||
* Set the accessToken. | ||
*/ | ||
public BaatoSearchService setAccessToken(@NonNull String accessToken) { | ||
this.accessToken = accessToken; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the query to search. | ||
*/ | ||
public BaatoSearchService setQuery(@NonNull String query) { | ||
this.query = query; | ||
return this; | ||
} | ||
|
||
/** | ||
* Method to set the UpdateListener for the AppUpdaterUtils actions | ||
* | ||
* @param baatoSearchRequestListener the listener to be notified | ||
* @return this | ||
*/ | ||
public BaatoSearchService withListener(BaatoSearchRequestListener baatoSearchRequestListener) { | ||
this.baatoSearchRequestListener = baatoSearchRequestListener; | ||
return this; | ||
} | ||
|
||
public void doSearch() { | ||
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class); | ||
queryAPI.searchQuery(query).enqueue(new Callback<List<Place>>() { | ||
@Override | ||
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) { | ||
if (response.isSuccessful() && response.body() != null) | ||
baatoSearchRequestListener.onSuccess(response.body()); | ||
else{ | ||
try { | ||
baatoSearchRequestListener.onFailed(new Throwable(response.errorBody().string())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<List<Place>> call, Throwable throwable) { | ||
baatoSearchRequestListener.onFailed(throwable); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.