Skip to content

Commit

Permalink
Move to Android provided GeoCoder
Browse files Browse the repository at this point in the history
  • Loading branch information
newmanw committed Oct 22, 2018
1 parent aef36a9 commit b76413c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 29 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ All notable changes to this project will be documented in this file.
Adheres to [Semantic Versioning](http://semver.org/).

---
## 6.2.1 (TBD)
## 6.2.2 (TBD)

* TBD

##### Features

##### Bug Fixes

## [6.2.1](https://github.com/ngageoint/mage-android/releases/tag/6.2.1) (10-22-2018)

##### Features
* Move to Android provided geocoder. The provided geocoder does not need an API key, at least for now.

##### Bug Fixes

## [6.2.0](https://github.com/ngageoint/mage-android/releases/tag/6.2.0) (09-18-2018)

##### Features
Expand Down
7 changes: 3 additions & 4 deletions mage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ apply plugin: 'maven-publish'

group 'mil.nga.giat.mage'
archivesBaseName = 'mage-android'
version '6.2.0'
version '6.2.1'
ext {
versionCode = 56
versionCode = 57
sourceRefspec = Grgit.open().head().id
}

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

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

task androidArtifactVersion {
Expand Down
Binary file removed mage/libs/GeocoderPlus.jar
Binary file not shown.
2 changes: 0 additions & 2 deletions mage/src/main/java/mil/nga/giat/mage/login/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,6 @@ public void onAuthentication(AccountStatus accountStatus) {
Log.e(LOG_NAME, "Could not hash password", e);
}

PreferenceHelper.getInstance(getApplicationContext()).logKeyValuePairs();

final boolean sameUser = sharedPreferences.getString(getApplicationContext().getString(mil.nga.giat.mage.sdk.R.string.usernameKey), "").equals(currentUsername);
final boolean preserveActivityStack = sameUser && mContinueSession;

Expand Down
33 changes: 20 additions & 13 deletions mage/src/main/java/mil/nga/giat/mage/map/GeocoderTask.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package mil.nga.giat.mage.map;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.bricolsoftconsulting.geocoderplus.Address;
import com.bricolsoftconsulting.geocoderplus.Geocoder;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

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

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

private static final int MAX_ADDRESS_LINES = 3;
private static final int MAX_ADDRESS_ZOOM = 18;

private Context context;

// reference to map
Expand Down Expand Up @@ -53,30 +56,30 @@ protected SearchResults doInBackground(String... params) {
.title("MGRS")
.snippet(searchString);

results.bounds = new LatLngBounds(position, position);
results.zoom = 18;
} catch (ParseException e) {
Log.e(LOG_NAME, "Problem parsing mgrs string", e);
}
} else {
// Creating an instance of Geocoder class
Geocoder geocoder = new Geocoder();
Geocoder geocoder = new Geocoder(context);

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

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

results.markerOptions = new MarkerOptions()
.position(new LatLng(address.getLatitude(), address.getLongitude()))
.title(searchString)
.snippet(address.getFormattedAddress());
.snippet(address.getAddressLine(0));

}
} catch (IOException e) {
Log.e(LOG_NAME, "Problem executing search.");
Log.e(LOG_NAME, "Problem executing search.", e);
}
}

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

if (results.markerOptions == null) {
if(ConnectivityUtility.isOnline(context)) {
Toast.makeText(context, "Unknown location", Toast.LENGTH_LONG).show();
Toast.makeText(context, "Could not find address.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "No connectivity, try again later.", Toast.LENGTH_LONG).show();
}
Expand All @@ -104,12 +107,16 @@ protected void onPostExecute(SearchResults results) {
m.showInfoWindow();
}

map.animateCamera(CameraUpdateFactory.newLatLngBounds(results.bounds, 10));
CameraPosition position = CameraPosition.builder()
.target(results.markerOptions.getPosition())
.zoom(results.zoom).build();

map.animateCamera(CameraUpdateFactory.newCameraPosition(position));
}
}

public class SearchResults {
public MarkerOptions markerOptions;
public LatLngBounds bounds;
public int zoom;
}
}
23 changes: 14 additions & 9 deletions mage/src/main/java/mil/nga/giat/mage/map/MapFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.os.AsyncTask;
Expand Down Expand Up @@ -232,16 +233,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
zoomToLocationButton = (FloatingActionButton) view.findViewById(R.id.zoom_button);

searchButton = (FloatingActionButton) view.findViewById(R.id.map_search_button);
Drawable drawable = DrawableCompat.wrap(searchButton.getDrawable());
searchButton.setImageDrawable(drawable);
DrawableCompat.setTintList(drawable, AppCompatResources.getColorStateList(getContext(), R.color.toggle_button_selected));
if (Geocoder.isPresent()) {
Drawable drawable = DrawableCompat.wrap(searchButton.getDrawable());
searchButton.setImageDrawable(drawable);
DrawableCompat.setTintList(drawable, AppCompatResources.getColorStateList(getContext(), R.color.toggle_button_selected));

searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
search();
}
});
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
search();
}
});
} else {
searchButton.setVisibility(View.GONE);
}

view.findViewById(R.id.new_observation_button).setOnClickListener(new OnClickListener() {
@Override
Expand Down

0 comments on commit b76413c

Please sign in to comment.