Skip to content

Commit b3b0243

Browse files
committed
added service for reverse geocoding api integration
1 parent d80e20c commit b3b0243

File tree

11 files changed

+231
-89
lines changed

11 files changed

+231
-89
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ dependencies {
3232
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3333

3434
//toaster library
35-
implementation 'com.github.Ichchhie:Toaster-Library:0.3.0'
35+
implementation 'com.github.Ichchhie:Toaster-Library:0.4.0'
3636

3737
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'){
3838
exclude group: 'group_name', module: 'module_name'
3939
}
4040

41-
// implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.42.5'
41+
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.42.5'
4242
// implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.5'
4343
//graphhopper navigation
4444
// implementation 'com.graphhopper.navigation:navigation-android:0.1.0'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.kathmandulivinglabs.osmnavigationapp;
2+
3+
public interface Constants {
4+
String TAG = "minion";
5+
int REVERSE_GEO_CODE_RADIUS = 2;
6+
String TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJpY2hjaGhhIiwiZXhwIjoxNTgzMzgyOTM0LCJpYXQiOjE1ODE2NTQ5MzR9.MR0K8MBvoWWxvTIoaOJS3fwYyTkghEalv5yRVCrGh_4";
7+
}

app/src/main/java/com/kathmandulivinglabs/osmnavigationapp/MainActivity.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.kathmandulivinglabs.osmnavigationapp;
22

3-
import androidx.annotation.NonNull;
4-
import androidx.appcompat.app.AppCompatActivity;
5-
63
import android.os.Bundle;
74
import android.util.Log;
85

9-
import com.google.android.material.snackbar.Snackbar;
10-
import com.kathmandulivinglabs.navigationlibrary.BaatoUtil;
11-
import com.kathmandulivinglabs.navigationlibrary.ToasterMessage;
6+
import androidx.annotation.NonNull;
7+
import androidx.appcompat.app.AppCompatActivity;
8+
129
import com.kathmandulivinglabs.navigationlibrary.models.Geometry;
10+
import com.kathmandulivinglabs.navigationlibrary.services.Baato;
11+
import com.kathmandulivinglabs.navigationlibrary.services.ToasterMessage;
12+
import com.kathmandulivinglabs.navigationlibrary.utilities.BaatoUtil;
1313
import com.mapbox.api.directions.v5.models.DirectionsResponse;
1414
import com.mapbox.api.directions.v5.models.DirectionsRoute;
1515
import com.mapbox.geojson.Point;
@@ -22,7 +22,6 @@
2222
import com.mapbox.mapboxsdk.maps.MapboxMap;
2323
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
2424
import com.mapbox.mapboxsdk.maps.Style;
25-
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
2625
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;
2726

2827
import java.util.List;
@@ -37,7 +36,7 @@ public class MainActivity extends AppCompatActivity implements OnMapReadyCallbac
3736
private static final String TAG = "apple";
3837
private MapboxMap mapboxMap;
3938
private MapView mapView;
40-
private NavigationMapRoute navigationMapRoute;
39+
private NavigationRoute navigationMapRoute;
4140
String encoded = "wv{gD_`lhOQvAO^c@h@Yj@IZKhADXj@|ABrAElB@NLLp@LHFDJJvDb@pBx@~B`AjBBP@fCArBW|KSxEQbHGbAYhBKVmA`C}A`EuBrGcAxC}@hBA^BJb@`@dBr@tBbAh@RdDbBs@fCYxAmBnKy@`F_Gj[]zBS~AWjDC~AA|BBbBj@|JpB~YRrDbAjONlDD~AAbCuArj@o@nSkB~w@CzB{@x\\e@rLa@jN@zBO|DE|EQjBKp@W~@Sf@o@dAs@x@i@d@_@RkAj@_AP_AJmCDkBD}IDoFF_ETc@@iARyAf@UKa@_@YKk@KuBGu@Kq@MkA[k@SsB{@wCwAgAo@g@SsDiBa@OcJmE{IcEiAm@kJmEmAc@U?QA[IUK]EmI_@wBCk@Dm@FiCt@k@ViNvJ_BlAcAj@{@Xc@JuALsGN{@F_@Da@NeAn@WXWb@]fAIf@Al@Bt@`AvKVhDDpAMjB[jASb@yAzBiAvAuCfEYxAe@SmE}AsGeA_FiBwG_CsB_@sGq@{AWcA]eASuC{@g@IiDs@_BWy@FiG`BqCx@sFvA{JlC_APq@DqA?[CcAOgCg@qFqAgGkA{@Gk@@i@Dg@Je@NmAl@_^~R^p@lAlAdAv@^T~Al@t@l@F?b@MjChANBl@ATIDCFl@APNH?Ho@`CTf@HJ`@FJN?Je@fA[d@CJBJHJ@POv@HPFVd@ZBJAJa@v@bAf@JjAw@`@yAf@s@d@SHQAAf@c@C@p@YAm@R?n@SPkAPAB?|@g@HCLaAB";
4241

4342
@Override
@@ -50,6 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
5049
mapView.getMapAsync(this);
5150
ToasterMessage.s(this, "Hello Good Morning");
5251
Geometry geometry = BaatoUtil.getGeoJsonFromEncodedPolyLine(encoded);
52+
Log.d(TAG, "onCreate: " + Baato.search(Constants.TOKEN, "chardhunga").toString());
5353
NavigationRoute.builder(this)
5454
.accessToken(Mapbox.getAccessToken())
5555
.origin(Point.fromLngLat(85.4278774, 27.6721352))
@@ -70,9 +70,9 @@ public void onMapReady(@NonNull MapboxMap mapboxMap) {
7070
this.mapboxMap = mapboxMap;
7171
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
7272
initializeLocationComponent(mapboxMap);
73-
navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap);
73+
// navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap);
7474
mapboxMap.addOnMapLongClickListener(this);
75-
Snackbar.make(mapView, "Long press to select route", Snackbar.LENGTH_SHORT).show();
75+
// Snackbar.make(mapView, "Long press to select route", Snackbar.LENGTH_SHORT).show();
7676
});
7777
}
7878

@@ -92,7 +92,7 @@ public void onResponse(Call<DirectionsResponse> call, Response<DirectionsRespons
9292
&& response.body() != null
9393
&& !response.body().routes().isEmpty()) {
9494
List<DirectionsRoute> routes = response.body().routes();
95-
navigationMapRoute.addRoutes(routes);
95+
// navigationMapRoute.addRoutes(routes);
9696
}
9797
}
9898

@@ -111,18 +111,18 @@ public void onResume() {
111111
protected void onStart() {
112112
super.onStart();
113113
mapView.onStart();
114-
if (navigationMapRoute != null) {
115-
navigationMapRoute.onStart();
116-
}
114+
// if (navigationMapRoute != null) {
115+
// navigationMapRoute.onStart();
116+
// }
117117
}
118118

119119
@Override
120120
protected void onStop() {
121121
super.onStop();
122122
mapView.onStop();
123-
if (navigationMapRoute != null) {
124-
navigationMapRoute.onStop();
125-
}
123+
// if (navigationMapRoute != null) {
124+
// navigationMapRoute.onStop();
125+
// }
126126
}
127127

128128
@Override

toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/models/Centroid.java

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.kathmandulivinglabs.navigationlibrary.models;
2+
3+
public class Geocode {
4+
public double lat,lon;
5+
6+
public Geocode(double lat, double lon) {
7+
this.lat = lat;
8+
this.lon = lon;
9+
}
10+
}

toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/models/Place.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Place {
1414
private Integer searchRank;
1515
private Integer addressRank;
1616
private String geometryType;
17-
private Centroid centroid;
17+
private Geocode centroid;
1818

1919
private List<String> tags;
2020
private String country;
@@ -110,11 +110,11 @@ public void setGeometryType(String geometryType) {
110110
this.geometryType = geometryType;
111111
}
112112

113-
public Centroid getCentroid() {
113+
public Geocode getCentroid() {
114114
return centroid;
115115
}
116116

117-
public void setCentroid(Centroid centroid) {
117+
public void setCentroid(Geocode centroid) {
118118
this.centroid = centroid;
119119
}
120120

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.kathmandulivinglabs.navigationlibrary.responses;
2+
3+
public class ReverseGeoCodeResponse {
4+
}

toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/services/Baato.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import static android.content.ContentValues.TAG;
88

99
public class Baato {
10-
public static Object search(String api_key, String query) {
11-
Search search = new Search(api_key, query);
12-
Log.d(TAG, "search:string " + search.doSearch().equals(String.class));
13-
Log.d(TAG, "search:list " + search.doSearch().equals(List.class));
14-
return search.doSearch();
15-
}
10+
// public static Object search(String api_key, String query) {
11+
// SearchQuery searchQuery = new SearchQuery(api_key, query);
12+
// Log.d(TAG, "search:string " + searchQuery.doSearch().equals(String.class));
13+
// Log.d(TAG, "search:list " + searchQuery.doSearch().equals(List.class));
14+
// return searchQuery.doSearch();
15+
// }
1616
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.kathmandulivinglabs.navigationlibrary.services;
2+
3+
import android.content.Context;
4+
import android.location.Geocoder;
5+
6+
import androidx.annotation.NonNull;
7+
8+
import com.kathmandulivinglabs.navigationlibrary.application.App;
9+
import com.kathmandulivinglabs.navigationlibrary.models.Geocode;
10+
import com.kathmandulivinglabs.navigationlibrary.models.Geometry;
11+
import com.kathmandulivinglabs.navigationlibrary.models.Place;
12+
import com.kathmandulivinglabs.navigationlibrary.requests.QueryAPI;
13+
14+
import java.io.IOException;
15+
import java.util.List;
16+
17+
import retrofit2.Call;
18+
import retrofit2.Callback;
19+
import retrofit2.Response;
20+
21+
public class BaatoReverseGeoCodeService {
22+
private Context context;
23+
private BaatoReverseGeoCodeRequestListener baatoSearchRequestListener;
24+
private String accessToken;
25+
private int radius;
26+
private Geocode geocode;
27+
28+
public interface BaatoReverseGeoCodeRequestListener {
29+
/**
30+
* onSuccess method called after it is successful
31+
* onFailed method called if it can't places
32+
*/
33+
void onSuccess(List<Place> places);
34+
35+
void onFailed(Throwable error);
36+
}
37+
38+
public BaatoReverseGeoCodeService(Context context) {
39+
this.context = context;
40+
}
41+
42+
/**
43+
* Set the accessToken.
44+
*/
45+
public BaatoReverseGeoCodeService setAccessToken(@NonNull String accessToken) {
46+
this.accessToken = accessToken;
47+
return this;
48+
}
49+
50+
/**
51+
* Set the query to search.
52+
*/
53+
public BaatoReverseGeoCodeService setGeoCode(@NonNull Geocode geoCode) {
54+
this.geocode = geoCode;
55+
return this;
56+
}
57+
58+
public BaatoReverseGeoCodeService setRadius(@NonNull int radius) {
59+
this.radius = radius;
60+
return this;
61+
}
62+
63+
/**
64+
* Method to set the UpdateListener for the AppUpdaterUtils actions
65+
*
66+
* @param baatoSearchRequestListener the listener to be notified
67+
* @return this
68+
*/
69+
public BaatoReverseGeoCodeService withListener(BaatoReverseGeoCodeRequestListener baatoSearchRequestListener) {
70+
this.baatoSearchRequestListener = baatoSearchRequestListener;
71+
return this;
72+
}
73+
74+
public void doReverseGeoCode() {
75+
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class);
76+
queryAPI.performReverseGeoCode(geocode.lat, geocode.lon, radius).enqueue(new Callback<List<Place>>() {
77+
@Override
78+
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
79+
if (response.isSuccessful() && response.body() != null)
80+
baatoSearchRequestListener.onSuccess(response.body());
81+
else {
82+
try {
83+
baatoSearchRequestListener.onFailed(new Throwable(response.errorBody().string()));
84+
} catch (IOException e) {
85+
e.printStackTrace();
86+
}
87+
}
88+
}
89+
90+
@Override
91+
public void onFailure(Call<List<Place>> call, Throwable throwable) {
92+
baatoSearchRequestListener.onFailed(throwable);
93+
}
94+
});
95+
}
96+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.kathmandulivinglabs.navigationlibrary.services;
2+
3+
import android.content.Context;
4+
5+
import androidx.annotation.NonNull;
6+
7+
import com.kathmandulivinglabs.navigationlibrary.application.App;
8+
import com.kathmandulivinglabs.navigationlibrary.models.Place;
9+
import com.kathmandulivinglabs.navigationlibrary.requests.QueryAPI;
10+
11+
import java.io.IOException;
12+
import java.util.List;
13+
14+
import retrofit2.Call;
15+
import retrofit2.Callback;
16+
import retrofit2.Response;
17+
18+
public class BaatoSearchService {
19+
private Context context;
20+
private BaatoSearchRequestListener baatoSearchRequestListener;
21+
private String accessToken, query;
22+
23+
public interface BaatoSearchRequestListener {
24+
/**
25+
* onSuccess method called after it is successful
26+
* onFailed method called if it can't places
27+
*/
28+
void onSuccess(List<Place> places);
29+
30+
void onFailed(Throwable error);
31+
}
32+
33+
public BaatoSearchService(Context context) {
34+
this.context = context;
35+
}
36+
37+
/**
38+
* Set the accessToken.
39+
*/
40+
public BaatoSearchService setAccessToken(@NonNull String accessToken) {
41+
this.accessToken = accessToken;
42+
return this;
43+
}
44+
45+
/**
46+
* Set the query to search.
47+
*/
48+
public BaatoSearchService setQuery(@NonNull String query) {
49+
this.query = query;
50+
return this;
51+
}
52+
53+
/**
54+
* Method to set the UpdateListener for the AppUpdaterUtils actions
55+
*
56+
* @param baatoSearchRequestListener the listener to be notified
57+
* @return this
58+
*/
59+
public BaatoSearchService withListener(BaatoSearchRequestListener baatoSearchRequestListener) {
60+
this.baatoSearchRequestListener = baatoSearchRequestListener;
61+
return this;
62+
}
63+
64+
public void doSearch() {
65+
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class);
66+
queryAPI.searchQuery(query).enqueue(new Callback<List<Place>>() {
67+
@Override
68+
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
69+
if (response.isSuccessful() && response.body() != null)
70+
baatoSearchRequestListener.onSuccess(response.body());
71+
else{
72+
try {
73+
baatoSearchRequestListener.onFailed(new Throwable(response.errorBody().string()));
74+
} catch (IOException e) {
75+
e.printStackTrace();
76+
}
77+
}
78+
}
79+
80+
@Override
81+
public void onFailure(Call<List<Place>> call, Throwable throwable) {
82+
baatoSearchRequestListener.onFailed(throwable);
83+
}
84+
});
85+
}
86+
}

0 commit comments

Comments
 (0)