Import to intelij, started updating to use maps v2

This commit is contained in:
2014-08-30 11:29:50 -04:00
parent 3ca7f800a6
commit 91970d0b97
18 changed files with 197 additions and 494 deletions

View File

@@ -4,5 +4,6 @@
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@@ -15,7 +15,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-sdk
android:minSdkVersion="7"
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<uses-feature

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager" forced_jdk="true">
<conelement value="com.android.ide.eclipse.adt.DEPENDENCIES" />
<src_description expected_position="1">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
<src_folder value="file://$MODULE_DIR$/gen" expected_position="1" />
<src_folder value="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK" expected_position="2" />
<src_folder value="com.android.ide.eclipse.adt.LIBRARIES" expected_position="3" />
</src_description>
</component>
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="LIBRARY_PROJECT" value="true" />
<option name="UPDATE_PROPERTY_FILES" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/bin/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/libs" type="java-resource" />
</content>
<orderEntry type="jdk" jdkName="Android 4.3 Google APIs" jdkType="Android SDK" />
<orderEntry type="module" module-name="google-play-services_lib" exported="" />
<orderEntry type="library" exported="" name="google-play-services" level="project" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

View File

@@ -9,4 +9,6 @@
android.library=true
# Project target.
target=Google Inc.:Google APIs:16
target=Google Inc.:Google APIs:18
android.library.reference.1=../../google-play-services_lib

View File

@@ -13,7 +13,7 @@
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="0rKmsWMM0D-LWOndcfwrmW-S0OXlnQl2SJCMeTg" />
android:apiKey="0rKmsWMM0D-IRAEgcSZEqwZCs_8AUwxjYjj0bnA" />
<ProgressBar
android:id="@+id/mapProgressBar"

View File

@@ -1,208 +0,0 @@
/**
* MapFragment.java
* @date Jan 7, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import com.TwentyCodes.android.location.MapView;
import com.TwentyCodes.android.location.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;
/**
* This map fragment will maintain a map view and all its functions
*
* @author ricky barrette
*/
public abstract class BaseMapFragment extends Fragment {
private MapView mMapView;
private boolean isGPSDialogEnabled;
private ProgressBar mProgress;
/**
* Creates a new MapFragment
*
* @author ricky barrette
*/
public BaseMapFragment() {
super();
}
public void addOverlay(final Overlay overlay) {
mMapView.getOverlays().add(overlay);
}
/**
* changes the map mode
*
* @author ricky barrette
*/
public void changeMapMode() {
mMapView.setSatellite(!mMapView.isSatellite());
}
/**
* Disables the Acquiring GPS dialog
*
* @author ricky barrette
*/
public void disableGPSProgess() {
isGPSDialogEnabled = false;
mProgress.setVisibility(View.GONE);
}
/**
* Enables the Acquiring GPS dialog if the location has not been acquired
*
* @author ricky barrette
*/
public void enableGPSProgess() {
isGPSDialogEnabled = true;
mProgress.setVisibility(View.VISIBLE);
}
/**
* @return mapview
* @author ricky barrette
*/
public MapView getMap() {
return mMapView;
}
/**
* Forces the map to redraw
*
* @author ricky barrette
*/
public void invalidate() {
mMapView.invalidate();
}
/**
* @return true if the GPS progress is showing
* @author ricky barrette
*/
public boolean isGPSProgessShowing() {
return isGPSDialogEnabled;
}
/**
* @return true if the map is in satellite mode
* @author ricky barrette
*/
public boolean isSatellite() {
return mMapView.isSatellite();
}
/**
* Called when the fragment view is first created (non-Javadoc)
*
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
* android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.base_map_fragment, container, false);
mMapView = (MapView) view.findViewById(R.id.mapview);
mMapView.setClickable(true);
mProgress = (ProgressBar) view.findViewById(R.id.mapProgressBar);
onMapViewCreate(mMapView);
return view;
}
/**
* Called when the mapview has been initialized. here you want to init and
* add your custom overlays
*
* @param map
* @author ricky barrette
*/
public abstract void onMapViewCreate(MapView map);
/**
* Removes an overlay from the mapview
*
* @param overlay
* @author ricky barrette
*/
public void removeOverlay(final Object overlay) {
mMapView.getOverlays().remove(overlay);
}
/**
* Enables or disables the built in zoom controls
*
* @param isShowing
* @author ricky barrette
*/
public void setBuiltInZoomControls(final boolean isShowing) {
mMapView.setBuiltInZoomControls(isShowing);
}
/**
* Sets where or not the map view is interactive
*
* @param isClickable
* @author ricky barrette
*/
public void setClickable(final boolean isClickable) {
mMapView.setClickable(isClickable);
}
/**
* Sets double tap zoom
*
* @param isDoubleTapZoonEnabled
* @author ricky barrette
*/
public void setDoubleTapZoonEnabled(final boolean isDoubleTapZoonEnabled) {
mMapView.setDoubleTapZoonEnabled(isDoubleTapZoonEnabled);
}
/**
* Sets the center of the map to the provided point
*
* @param point
* @author ricky barrette
*/
public boolean setMapCenter(final GeoPoint point) {
if (point == null)
return false;
mMapView.getController().setCenter(point);
return true;
}
/**
* Sets the view of the map. true is sat, false is map
*
* @param isSat
* @author ricky barrette
*/
public void setSatellite(final boolean isSat) {
mMapView.setSatellite(isSat);
}
/**
* Sets the zoom level of the map
*
* @param zoom
* @author ricky barrette
*/
public void setZoom(final int zoom) {
mMapView.getController().setZoom(zoom);
}
}

View File

@@ -6,15 +6,14 @@
*/
package com.TwentyCodes.android.fragments;
import java.util.ArrayList;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.TwentyCodes.android.overlays.DirectionsOverlay;
import com.google.android.maps.GeoPoint;
import android.app.ListFragment;
import java.util.ArrayList;
/**
* This fragment will be used to display directions to the user. When a specific
@@ -91,7 +90,6 @@ public class DirectionsListFragment extends ListFragment {
/**
* (non-Javadoc)
*
* @see android.support.v4.app.Fragment#onStart()
*/
@Override
public void onStart() {
@@ -111,7 +109,7 @@ public class DirectionsListFragment extends ListFragment {
}
/**
* Sets the text to be displayed while the list is empty
* Sets the text to be displayed while the list is .gitkeep
*
* @param text
* @author ricky barrette

View File

@@ -7,9 +7,10 @@
package com.TwentyCodes.android.fragments;
import com.TwentyCodes.android.location.CompassSensor.CompassListener;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.LatLngListener;
import com.TwentyCodes.android.location.MapView;
import com.TwentyCodes.android.overlays.UserOverlay;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.GeoPoint;
/**
@@ -19,10 +20,10 @@ import com.google.android.maps.GeoPoint;
*
* @author ricky barrette
*/
public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointLocationListener, CompassListener {
public class UserOverlayMapFragment extends MapFragment implements LatLngListener, CompassListener {
private UserOverlay mUserOverlay;
private GeoPointLocationListener mGeoPointLocationListener;
private LatLngListener mLatLngListener;
private CompassListener mCompassListener;
/**
@@ -63,7 +64,6 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
/**
* Called when the compass is updated (non-Javadoc)
*
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
*/
@Override
public void onCompassUpdate(final float bearing) {
@@ -73,8 +73,8 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
@Override
public void onFirstFix(final boolean isFistFix) {
if (mGeoPointLocationListener != null)
mGeoPointLocationListener.onFirstFix(isFistFix);
if (mLatLngListener != null)
mLatLngListener.onFirstFix(isFistFix);
}
/**
@@ -84,16 +84,14 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
*/
@Override
public void onLocationChanged(final GeoPoint point, final int accuracy) {
if (mGeoPointLocationListener != null)
mGeoPointLocationListener.onLocationChanged(point, accuracy);
if (mLatLngListener != null)
mLatLngListener.onLocationChanged(point, accuracy);
}
/**
* (non-Javadoc)
*
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onMapViewCreate(com.TwentyCodes.android.location.MapView)
*/
@Override
public void onMapViewCreate(final MapView map) {
mUserOverlay = new UserOverlay(map, getActivity().getApplicationContext());
mUserOverlay.registerListener(this);
@@ -107,26 +105,24 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
/**
* (non-Javadoc)
*
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onPause()
*/
@Override
public void onPause() {
super.onPause();
mUserOverlay.disableMyLocation();
removeOverlay(mUserOverlay);
// removeOverlay(mUserOverlay);
}
/**
* (non-Javadoc)
*
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onResume()
*/
@Override
public void onResume() {
super.onResume();
if (mUserOverlay != null) {
mUserOverlay.enableMyLocation();
addOverlay(mUserOverlay);
// addOverlay(mUserOverlay);
}
}
@@ -135,10 +131,10 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
*
* @author ricky barrette
*/
public void reorderOverlays() {
getMap().getOverlays().remove(mUserOverlay);
getMap().getOverlays().add(mUserOverlay);
}
// public void reorderOverlays() {
// getMap().getOverlays().remove(mUserOverlay);
// getMap().getOverlays().add(mUserOverlay);
// }
/**
* @param needleResId
@@ -173,7 +169,7 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
* @param listener
* @author ricky barrette
*/
public void setGeoPointLocationListener(final GeoPointLocationListener listener) {
mGeoPointLocationListener = listener;
public void setGeoPointLocationListener(final LatLngListener listener) {
mLatLngListener = listener;
}
}

View File

@@ -13,9 +13,8 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import com.TwentyCodes.android.debug.Debug;
import com.google.android.maps.GeoPoint;
import com.google.android.gms.maps.model.LatLng;
/**
* This class will be used for gathering location using android's location
@@ -27,7 +26,7 @@ public class AndroidGPS implements LocationListener {
private static final String TAG = "AndroidGPS";
private final LocationManager mLocationManager;
private GeoPointLocationListener mListener;
private LatLngListener mListener;
private LocationListener mLocationListener;
private boolean isFirstFix;
@@ -59,7 +58,7 @@ public class AndroidGPS implements LocationListener {
*
* @author ricky barrette
*/
public void enableLocationUpdates(final GeoPointLocationListener listener) {
public void enableLocationUpdates(final LatLngListener listener) {
if (Debug.DEBUG)
Log.d(TAG, "enableLocationUpdates()");
if (mListener == null) {
@@ -93,7 +92,7 @@ public class AndroidGPS implements LocationListener {
@Override
public void onLocationChanged(final Location location) {
if (mListener != null) {
mListener.onLocationChanged(new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6)), (int) location.getAccuracy());
mListener.onLocationChanged(new LatLng(location.getLatitude(), location.getLongitude()), (int) location.getAccuracy());
mListener.onFirstFix(isFirstFix);
}

View File

@@ -20,14 +20,9 @@
*/
package com.TwentyCodes.android.location;
import com.google.android.gms.maps.model.LatLng;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Point;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
/**
* This class contains common tools for computing common geological problems
@@ -70,18 +65,14 @@ public class GeoUtils {
* degrees East of true north
*
* @param p1
* source geopoint
* source LatLng
* @param p2
* destination geopoint
* destination LatLng
* @return the bearing of p2 in relationship from p1 in degrees East
* @author Google Inc.
*/
public static Double bearing(final GeoPoint p1, final GeoPoint p2) {
final double lat1 = p1.getLatitudeE6() / MILLION;
final double lon1 = p1.getLongitudeE6() / MILLION;
final double lat2 = p2.getLatitudeE6() / MILLION;
final double lon2 = p2.getLongitudeE6() / MILLION;
return bearing(lat1, lon1, lat2, lon2);
public static Double bearing(final LatLng p1, final LatLng p2) {
return bearing(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
}
/**
@@ -99,7 +90,7 @@ public class GeoUtils {
* @return Degrees East of dest location
* @author ricky barrette
*/
public static float calculateBearing(final GeoPoint user, final GeoPoint dest, float bearing) {
public static float calculateBearing(final LatLng user, final LatLng dest, float bearing) {
if (user == null || dest == null)
return bearing;
@@ -115,24 +106,24 @@ public class GeoUtils {
}
/**
* Calculates a geopoint x meters away of the geopoint supplied. The new
* geopoint shares the same latitude as geopoint point, this way they are on
* Calculates a LatLng x meters away of the LatLng supplied. The new
* LatLng shares the same latitude as LatLng point, this way they are on
* the same latitude arc.
*
* @param point
* central geopoint
* central LatLng
* @param distance
* in meters from the geopoint
* @return geopoint that is x meters away from the geopoint supplied
* in meters from the LatLng
* @return LatLng that is x meters away from the LatLng supplied
* @author ricky barrette
*/
public static GeoPoint distanceFrom(final GeoPoint point, double distance) {
public static LatLng distanceFrom(final LatLng point, double distance) {
// convert meters into kilometers
distance = distance / 1000;
// convert lat and lon of geopoint to radians
final double lat1Rad = Math.toRadians(point.getLatitudeE6() / 1e6);
final double lon1Rad = Math.toRadians(point.getLongitudeE6() / 1e6);
// convert lat and lon of LatLng to radians
final double lat1Rad = Math.toRadians(point.latitude);
final double lon1Rad = Math.toRadians(point.longitude);
/*
* kilometers =
@@ -148,7 +139,7 @@ public class GeoUtils {
* NOTE: sec(x) = 1/cos(x)
*
* NOTE: that lat2Rad is = lat1Rad because we want to keep the new
* geopoint on the same lat arc therefore i saw no need to create a new
* LatLng on the same lat arc therefore i saw no need to create a new
* variable for lat2Rad, and simply inputed lat1Rad in place of lat2Rad
* in the equation
*
@@ -158,8 +149,8 @@ public class GeoUtils {
*/
final double lon2Rad = lon1Rad + Math.acos(Math.cos(distance / 6371) * (1 / Math.cos(lat1Rad)) * (1 / Math.cos(lat1Rad)) - Math.tan(lat1Rad) * Math.tan(lat1Rad));
// return a geopoint that is x meters away from the geopoint supplied
return new GeoPoint(point.getLatitudeE6(), (int) (Math.toDegrees(lon2Rad) * 1e6));
// return a LatLng that is x meters away from the LatLng supplied
return new LatLng(point.latitude, (int) (Math.toDegrees(lon2Rad) * 1e6));
}
/**
@@ -193,16 +184,12 @@ public class GeoUtils {
* @return the distance between to p1 and p2
* @author Google Inc.
*/
public static double distanceKm(final GeoPoint p1, final GeoPoint p2) {
public static double distanceKm(final LatLng p1, final LatLng p2) {
// if we are handed a null, return -1 so we don't break
if (p1 == null || p2 == null)
return -1;
final double lat1 = p1.getLatitudeE6() / MILLION;
final double lon1 = p1.getLongitudeE6() / MILLION;
final double lat2 = p2.getLatitudeE6() / MILLION;
final double lon2 = p2.getLongitudeE6() / MILLION;
return distanceKm(lat1, lon1, lat2, lon2);
return distanceKm(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
}
/**
@@ -253,71 +240,80 @@ public class GeoUtils {
* @return true if the circles intersect
* @author ricky barrette
*/
public static boolean isIntersecting(final GeoPoint userPoint, final float accuracyRadius, final GeoPoint locationPoint, final float locationRadius,
public static boolean isIntersecting(final LatLng userPoint, final float accuracyRadius, final LatLng locationPoint, final float locationRadius,
final float fudgeFactor) {
if (accuracyRadius + locationRadius - fudgeFactor > distanceKm(locationPoint, userPoint))
return true;
return false;
}
/**
* determines when the specified point is off the map
*
* @param point
* @return true is the point is off the map
* @author ricky barrette
*/
public static boolean isPointOffMap(final MapView map, final GeoPoint point) {
if (map == null)
return false;
if (point == null)
return false;
final GeoPoint center = map.getMapCenter();
final double distance = GeoUtils.distanceKm(center, point);
final double distanceLat = GeoUtils.distanceKm(center, new GeoPoint(center.getLatitudeE6() + map.getLatitudeSpan() / 2, center.getLongitudeE6()));
final double distanceLon = GeoUtils.distanceKm(center, new GeoPoint(center.getLatitudeE6(), center.getLongitudeE6() + map.getLongitudeSpan() / 2));
if (distance > distanceLat || distance > distanceLon)
return true;
return false;
}
/**
* computes a geopoint the is the central geopoint between p1 and p1
*
* @param p1
* first geopoint
* @param p2
* second geopoint
* @return a MidPoint object
* @author ricky barrette
*/
public static MidPoint midPoint(final GeoPoint p1, final GeoPoint p2) {
int minLatitude = (int) (+81 * 1E6);
int maxLatitude = (int) (-81 * 1E6);
int minLongitude = (int) (+181 * 1E6);
int maxLongitude = (int) (-181 * 1E6);
final List<Point> mPoints = new ArrayList<Point>();
int latitude = p1.getLatitudeE6();
int longitude = p1.getLongitudeE6();
if (latitude != 0 && longitude != 0) {
minLatitude = minLatitude > latitude ? latitude : minLatitude;
maxLatitude = maxLatitude < latitude ? latitude : maxLatitude;
minLongitude = minLongitude > longitude ? longitude : minLongitude;
maxLongitude = maxLongitude < longitude ? longitude : maxLongitude;
mPoints.add(new Point(latitude, longitude));
}
latitude = p2.getLatitudeE6();
longitude = p2.getLongitudeE6();
if (latitude != 0 && longitude != 0) {
minLatitude = minLatitude > latitude ? latitude : minLatitude;
maxLatitude = maxLatitude < latitude ? latitude : maxLatitude;
minLongitude = minLongitude > longitude ? longitude : minLongitude;
maxLongitude = maxLongitude < longitude ? longitude : maxLongitude;
mPoints.add(new Point(latitude, longitude));
}
return new MidPoint(new GeoPoint((maxLatitude + minLatitude) / 2, (maxLongitude + minLongitude) / 2), minLatitude, minLongitude, maxLatitude, maxLongitude);
}
// /**
// * determines when the specified point is off the map
// *
// * @param point
// * @return true is the point is off the map
// * @author ricky barrette
// */
// public static boolean isPointOffMap(final GoogleMap map, final LatLng point) {
//
// VisibleRegion vr = map.getProjection().getVisibleRegion();
// double left = vr.latLngBounds.southwest.longitude;
// double top = vr.latLngBounds.northeast.latitude;
// double right = vr.latLngBounds.northeast.longitude;
// double bottom = vr.latLngBounds.southwest.latitude;
//
// if (map == null)
// return false;
// if (point == null)
// return false;
// final LatLng center = map.getCameraPosition().target;
// final double distance = GeoUtils.distanceKm(center, point);
// final double distanceLat = GeoUtils.distanceKm(center, new LatLng(center.latitude + map.getLatitudeSpan() / 2, center.longitude));
// final double distanceLon = GeoUtils.distanceKm(center, new LatLng(center.latitude, center.longitude + map.getLongitudeSpan() / 2));
// if (distance > distanceLat || distance > distanceLon)
// return true;
// return false;
//
// return map.getProjection().toScreenLocation()
// }
//
// /**
// * computes a LatLng the is the central LatLng between p1 and p1
// *
// * @param p1
// * first LatLng
// * @param p2
// * second LatLng
// * @return a MidPoint object
// * @author ricky barrette
// */
// public static MidPoint midpoint(final LatLng p1, final LatLng p2) {
//// double minLatitude = +81 * 1E6;
//// double maxLatitude = -81 * 1E6;
//// double minLongitude = +181 * 1E6;
//// double maxLongitude = -181 * 1E6;
//// final List<Point> mPoints = new ArrayList<Point>();
//// if (p1.latitude != 0 && p1.longitude != 0) {
//// minLatitude = minLatitude > p1.latitude ? p1.latitude : minLatitude;
//// maxLatitude = maxLatitude < p1.latitude ? p1.latitude : maxLatitude;
//// minLongitude = minLongitude > p1.longitude ? p1.longitude : minLongitude;
//// maxLongitude = maxLongitude < p1.longitude ? p1.longitude : maxLongitude;
//// mPoints.add(new Point(p1.latitude, p1.longitude));
//// }
////
//// if (p2.latitude != 0 && p2.longitude != 0) {
//// minLatitude = minLatitude > p2.latitude ? p2.latitude : minLatitude;
//// maxLatitude = maxLatitude < p2.latitude ? p2.latitude : maxLatitude;
//// minLongitude = minLongitude > p2.longitude ? p2.longitude : minLongitude;
//// maxLongitude = maxLongitude < p2.longitude ? p2.longitude : maxLongitude;
//// mPoints.add(new Point(p2.latitude, p2.longitude));
//// }
//// return new MidPoint(new LatLng((maxLatitude + minLatitude) / 2, (maxLongitude + minLongitude) / 2), minLatitude, minLongitude, maxLatitude, maxLongitude);
// LatLngBounds.Builder latLngBounds = new LatLngBounds.Builder();
// latLngBounds.include(p1);
// latLngBounds.include(p2);
// return new MidPoint(latLngBounds.build().getCenter()
// }
/**
* converts radians to bearing

View File

@@ -5,15 +5,15 @@
*/
package com.TwentyCodes.android.location;
import com.google.android.maps.GeoPoint;
import com.google.android.gms.maps.model.LatLng;
/**
* this interface will be used to interface with skyhook sdk with the rest of
* this interface will be used to interface with the GPS sdk with the rest of
* the application
*
* @author ricky barrette
*/
public interface GeoPointLocationListener {
public interface LatLngListener {
/**
* Called when first fix is aquired
@@ -30,5 +30,5 @@ public interface GeoPointLocationListener {
* @param accuracy
* @author ricky barrette
*/
public void onLocationChanged(GeoPoint point, int accuracy);
public void onLocationChanged(LatLng point, int accuracy);
}

View File

@@ -1,56 +0,0 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Nov 30, 2010
*/
package com.TwentyCodes.android.location;
import com.google.android.maps.GeoPoint;
/**
* This MidPoint object will hold the information form the calculations
* performed by GeoUtils.midPoint().
*
* @author ricky barrette
*/
public class MidPoint {
private final int mMinLatitude;
private final int mMaxLatitude;
private final int mMinLongitude;
private final int mMaxLongitude;
private final GeoPoint mMidPoint;
/**
* Creates a new MidPoint
*
* @author ricky barrette
*/
public MidPoint(final GeoPoint midPoint, final int minLatitude, final int minLongitude, final int maxLatitude, final int maxLongitude) {
mMinLatitude = minLatitude;
mMaxLatitude = maxLatitude;
mMinLongitude = minLongitude;
mMaxLongitude = maxLongitude;
mMidPoint = midPoint;
}
/**
* returns the calculated midpoint
*
* @return
* @author ricky barrette
*/
public GeoPoint getMidPoint() {
return mMidPoint;
}
/**
* zooms the provided map view to the span of this mid point
*
* @param mMapView
* @author ricky barrette
*/
public void zoomToSpan(final com.google.android.maps.MapView mMapView) {
mMapView.getController().zoomToSpan(mMaxLatitude - mMinLatitude, mMaxLongitude - mMinLongitude);
}
}

View File

@@ -1,6 +1,6 @@
package com.TwentyCodes.android.location;
import com.google.android.maps.GeoPoint;
import com.google.android.gms.maps.model.LatLng;
/**
* This interface will be used to pass the selected location from the dialogs to
@@ -10,5 +10,5 @@ import com.google.android.maps.GeoPoint;
*/
public interface OnLocationSelectedListener {
public void onLocationSelected(GeoPoint point);
public void onLocationSelected(LatLng point);
}

View File

@@ -20,7 +20,7 @@ import android.util.Log;
import com.TwentyCodes.android.debug.Debug;
import com.TwentyCodes.android.location.CompassSensor.CompassListener;
import com.TwentyCodes.android.location.GeoPointLocationListener;
import com.TwentyCodes.android.location.LatLngListener;
import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.R;
import com.google.android.maps.GeoPoint;
@@ -33,7 +33,7 @@ import com.google.android.maps.Projection;
*
* @author ricky barrette
*/
public abstract class BaseUserOverlay extends Overlay implements GeoPointLocationListener, CompassListener {
public abstract class BaseUserOverlay extends Overlay implements LatLngListener, CompassListener {
/**
* This thread is responsible for animating the user icon
@@ -114,7 +114,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
private final Context mContext;
private final MapView mMapView;
private boolean isFistFix = true;
private GeoPointLocationListener mListener;
private LatLngListener mListener;
public boolean isFollowingUser = true;
private final CompasOverlay mCompass;
private boolean isCompassEnabled;
@@ -441,7 +441,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
* @param listener
* @author Ricky Barrette
*/
public void registerListener(final GeoPointLocationListener listener) {
public void registerListener(final LatLngListener listener) {
Log.d(TAG, "registerListener()");
if (mListener == null)
mListener = listener;

View File

@@ -5,20 +5,9 @@
package com.TwentyCodes.android.overlays;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.RectF;
import com.TwentyCodes.android.location.GeoUtils;
import com.TwentyCodes.android.location.OnLocationSelectedListener;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
/**
* This class will used to draw a radius of a specified size in a specified
@@ -26,13 +15,9 @@ import com.google.android.maps.Projection;
*
* @author ricky barrette
*/
public class RadiusOverlay extends Overlay {
public class RadiusOverlay {
public OverlayItem mOverlayItem;
private GeoPoint mPoint;
private float mRadius = 0;
private int mColor = Color.GREEN;
private GeoPoint mRadiusPoint;
private final CircleOptions mCircleOptions;
private OnLocationSelectedListener mListener;
/**
@@ -41,6 +26,7 @@ public class RadiusOverlay extends Overlay {
* @author ricky barrette
*/
public RadiusOverlay() {
mCircleOptions = new CircleOptions();
}
/**
@@ -55,101 +41,48 @@ public class RadiusOverlay extends Overlay {
* desired color of the radius from Color API
* @author ricky barrette
*/
public RadiusOverlay(final GeoPoint point, final float radius, final int color) {
mPoint = point;
mRadius = radius;
mColor = color;
}
/**
* draws a specific radius on the mapview that is handed to it
*
* @param canvas
* canvas to be drawn on
* @param mapView
* @param shadow
* @param when
*/
@Override
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
if (mPoint != null) {
final Paint paint = new Paint();
final Point center = new Point();
final Point left = new Point();
final Projection projection = mapView.getProjection();
/*
* Calculate a geopoint that is "radius" meters away from geopoint
* point and convert the given GeoPoint and leftGeo to onscreen
* pixel coordinates, relative to the top-left of the MapView that
* provided this Projection.
*/
mRadiusPoint = GeoUtils.distanceFrom(mPoint, mRadius);
projection.toPixels(mRadiusPoint, left);
projection.toPixels(mPoint, center);
/*
* get radius of the circle being drawn by
*/
int circleRadius = center.x - left.x;
if (circleRadius <= 0)
circleRadius = left.x - center.x;
/*
* paint a circle on the map
*/
paint.setAntiAlias(true);
paint.setStrokeWidth(2.0f);
paint.setColor(mColor);
paint.setStyle(Style.STROKE);
canvas.drawCircle(center.x, center.y, circleRadius, paint);
// draw a dot over the geopoint
final RectF oval = new RectF(center.x - 2, center.y - 2, center.x + 2, center.y + 2);
canvas.drawOval(oval, paint);
// fill the radius with a nice green
paint.setAlpha(25);
paint.setStyle(Style.FILL);
canvas.drawCircle(center.x, center.y, circleRadius, paint);
}
public RadiusOverlay(final LatLng point, final double radius, final int color) {
mCircleOptions = new CircleOptions();
mCircleOptions.center(point);
mCircleOptions.radius(radius);
mCircleOptions.fillColor(color);
}
/**
* @return the selected location
* @author ricky barrette
*/
public GeoPoint getLocation() {
return mPoint;
public LatLng getLocation() {
return mCircleOptions.getCenter();
}
public int getZoomLevel() {
// GeoUtils.GeoUtils.distanceFrom(mPoint , mRadius)
return 0;
}
@Override
public boolean onTap(final GeoPoint p, final MapView mapView) {
mPoint = p;
if (mListener != null)
mListener.onLocationSelected(p);
return super.onTap(p, mapView);
}
//
// @Override
// public boolean onTap(final GeoPoint p, final MapView mapView) {
// mPoint = p;
// if (mListener != null)
// mListener.onLocationSelected(p);
// return super.onTap(p, mapView);
// }
/**
* @param color
* @author ricky barrette
*/
public void setColor(final int color) {
mColor = color;
mCircleOptions.fillColor(color);
}
/**
* @param location
* @author ricky barrette
*/
public void setLocation(final GeoPoint location) {
mPoint = location;
public void setLocation(final LatLng location) {
mCircleOptions.center(location);
}
public void setLocationSelectedListener(final OnLocationSelectedListener listener) {
@@ -162,7 +95,15 @@ public class RadiusOverlay extends Overlay {
* @author ricky barrette
* @param radius
*/
public void setRadius(final int radius) {
mRadius = radius;
public void setRadius(final double radius) {
mCircleOptions.radius(radius);
}
/**
*
* @return
*/
public CircleOptions getCircleOptions(){
return mCircleOptions;
}
}