Skip to content

Commit b76413c

Browse files
committed
Move to Android provided GeoCoder
1 parent aef36a9 commit b76413c

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ All notable changes to this project will be documented in this file.
33
Adheres to [Semantic Versioning](http://semver.org/).
44

55
---
6-
## 6.2.1 (TBD)
6+
## 6.2.2 (TBD)
77

88
* TBD
99

1010
##### Features
1111

1212
##### Bug Fixes
1313

14+
## [6.2.1](https://github.com/ngageoint/mage-android/releases/tag/6.2.1) (10-22-2018)
15+
16+
##### Features
17+
* Move to Android provided geocoder. The provided geocoder does not need an API key, at least for now.
18+
19+
##### Bug Fixes
20+
1421
## [6.2.0](https://github.com/ngageoint/mage-android/releases/tag/6.2.0) (09-18-2018)
1522

1623
##### Features

mage/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ apply plugin: 'maven-publish'
99

1010
group 'mil.nga.giat.mage'
1111
archivesBaseName = 'mage-android'
12-
version '6.2.0'
12+
version '6.2.1'
1313
ext {
14-
versionCode = 56
14+
versionCode = 57
1515
sourceRefspec = Grgit.open().head().id
1616
}
1717

@@ -184,7 +184,7 @@ dependencies {
184184
compile "com.google.android.gms:play-services-maps:$google_play_services_version"
185185

186186
// compile project(':sdk') // uncomment me to build locally, and see top-level build.gradle
187-
compile 'mil.nga.giat.mage:mage-android-sdk:6.2.0' // comment me to build locally
187+
compile 'mil.nga.giat.mage:mage-android-sdk:6.2.1' // comment me to build locally
188188
compile 'com.google.maps.android:android-maps-utils:0.5'
189189
compile 'mil.nga.geopackage.map:geopackage-android-map:1.4.1'
190190
compile 'org.ocpsoft.prettytime:prettytime:3.2.5.Final'
@@ -193,7 +193,6 @@ dependencies {
193193
compile 'com.google.android:flexbox:0.3.2'
194194
compile 'com.nulab-inc:zxcvbn:1.2.3'
195195
compile (name:'mgrs-0.0.2-release', ext:'aar')
196-
compile files('libs/GeocoderPlus.jar')
197196
}
198197

199198
task androidArtifactVersion {

mage/libs/GeocoderPlus.jar

-12.8 KB
Binary file not shown.

mage/src/main/java/mil/nga/giat/mage/login/LoginActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,6 @@ public void onAuthentication(AccountStatus accountStatus) {
608608
Log.e(LOG_NAME, "Could not hash password", e);
609609
}
610610

611-
PreferenceHelper.getInstance(getApplicationContext()).logKeyValuePairs();
612-
613611
final boolean sameUser = sharedPreferences.getString(getApplicationContext().getString(mil.nga.giat.mage.sdk.R.string.usernameKey), "").equals(currentUsername);
614612
final boolean preserveActivityStack = sameUser && mContinueSession;
615613

mage/src/main/java/mil/nga/giat/mage/map/GeocoderTask.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package mil.nga.giat.mage.map;
22

33
import android.content.Context;
4+
import android.location.Address;
5+
import android.location.Geocoder;
46
import android.os.AsyncTask;
57
import android.util.Log;
68
import android.widget.Toast;
79

8-
import com.bricolsoftconsulting.geocoderplus.Address;
9-
import com.bricolsoftconsulting.geocoderplus.Geocoder;
1010
import com.google.android.gms.maps.CameraUpdateFactory;
1111
import com.google.android.gms.maps.GoogleMap;
12+
import com.google.android.gms.maps.model.CameraPosition;
1213
import com.google.android.gms.maps.model.LatLng;
13-
import com.google.android.gms.maps.model.LatLngBounds;
1414
import com.google.android.gms.maps.model.Marker;
1515
import com.google.android.gms.maps.model.MarkerOptions;
1616

@@ -25,6 +25,9 @@ public class GeocoderTask extends AsyncTask<String, Void, GeocoderTask.SearchRes
2525

2626
private static final String LOG_NAME = GeocoderTask.class.getName();
2727

28+
private static final int MAX_ADDRESS_LINES = 3;
29+
private static final int MAX_ADDRESS_ZOOM = 18;
30+
2831
private Context context;
2932

3033
// reference to map
@@ -53,30 +56,30 @@ protected SearchResults doInBackground(String... params) {
5356
.title("MGRS")
5457
.snippet(searchString);
5558

56-
results.bounds = new LatLngBounds(position, position);
59+
results.zoom = 18;
5760
} catch (ParseException e) {
5861
Log.e(LOG_NAME, "Problem parsing mgrs string", e);
5962
}
6063
} else {
6164
// Creating an instance of Geocoder class
62-
Geocoder geocoder = new Geocoder();
65+
Geocoder geocoder = new Geocoder(context);
6366

6467
try {
6568
List<Address> addresses = geocoder.getFromLocationName(searchString, 1);
6669
if (addresses != null && addresses.size() > 0) {
6770
Address address = addresses.get(0);
6871

69-
LatLng southWestlatLng = new LatLng(address.getViewPort().getSouthWest().getLatitude(), address.getViewPort().getSouthWest().getLongitude());
70-
LatLng northEastlatLng = new LatLng(address.getViewPort().getNorthEast().getLatitude(), address.getViewPort().getNorthEast().getLongitude());
71-
results.bounds = new LatLngBounds(southWestlatLng, northEastlatLng);
72+
int addressLines = address.getMaxAddressLineIndex() + 1;
73+
results.zoom = MAX_ADDRESS_ZOOM - ((MAX_ADDRESS_LINES - addressLines) * 2);
7274

7375
results.markerOptions = new MarkerOptions()
7476
.position(new LatLng(address.getLatitude(), address.getLongitude()))
7577
.title(searchString)
76-
.snippet(address.getFormattedAddress());
78+
.snippet(address.getAddressLine(0));
79+
7780
}
7881
} catch (IOException e) {
79-
Log.e(LOG_NAME, "Problem executing search.");
82+
Log.e(LOG_NAME, "Problem executing search.", e);
8083
}
8184
}
8285

@@ -94,7 +97,7 @@ protected void onPostExecute(SearchResults results) {
9497

9598
if (results.markerOptions == null) {
9699
if(ConnectivityUtility.isOnline(context)) {
97-
Toast.makeText(context, "Unknown location", Toast.LENGTH_LONG).show();
100+
Toast.makeText(context, "Could not find address.", Toast.LENGTH_LONG).show();
98101
} else {
99102
Toast.makeText(context, "No connectivity, try again later.", Toast.LENGTH_LONG).show();
100103
}
@@ -104,12 +107,16 @@ protected void onPostExecute(SearchResults results) {
104107
m.showInfoWindow();
105108
}
106109

107-
map.animateCamera(CameraUpdateFactory.newLatLngBounds(results.bounds, 10));
110+
CameraPosition position = CameraPosition.builder()
111+
.target(results.markerOptions.getPosition())
112+
.zoom(results.zoom).build();
113+
114+
map.animateCamera(CameraUpdateFactory.newCameraPosition(position));
108115
}
109116
}
110117

111118
public class SearchResults {
112119
public MarkerOptions markerOptions;
113-
public LatLngBounds bounds;
120+
public int zoom;
114121
}
115122
}

mage/src/main/java/mil/nga/giat/mage/map/MapFragment.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.content.pm.PackageManager;
1010
import android.content.res.Configuration;
1111
import android.graphics.drawable.Drawable;
12+
import android.location.Geocoder;
1213
import android.location.Location;
1314
import android.location.LocationListener;
1415
import android.os.AsyncTask;
@@ -232,16 +233,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
232233
zoomToLocationButton = (FloatingActionButton) view.findViewById(R.id.zoom_button);
233234

234235
searchButton = (FloatingActionButton) view.findViewById(R.id.map_search_button);
235-
Drawable drawable = DrawableCompat.wrap(searchButton.getDrawable());
236-
searchButton.setImageDrawable(drawable);
237-
DrawableCompat.setTintList(drawable, AppCompatResources.getColorStateList(getContext(), R.color.toggle_button_selected));
236+
if (Geocoder.isPresent()) {
237+
Drawable drawable = DrawableCompat.wrap(searchButton.getDrawable());
238+
searchButton.setImageDrawable(drawable);
239+
DrawableCompat.setTintList(drawable, AppCompatResources.getColorStateList(getContext(), R.color.toggle_button_selected));
238240

239-
searchButton.setOnClickListener(new OnClickListener() {
240-
@Override
241-
public void onClick(View v) {
242-
search();
243-
}
244-
});
241+
searchButton.setOnClickListener(new OnClickListener() {
242+
@Override
243+
public void onClick(View v) {
244+
search();
245+
}
246+
});
247+
} else {
248+
searchButton.setVisibility(View.GONE);
249+
}
245250

246251
view.findViewById(R.id.new_observation_button).setOnClickListener(new OnClickListener() {
247252
@Override

0 commit comments

Comments
 (0)