diff --git a/LocationLib/.classpath b/LocationLib/.classpath index a4763d1..bb0c759 100644 --- a/LocationLib/.classpath +++ b/LocationLib/.classpath @@ -4,5 +4,6 @@ + diff --git a/LocationLib/AndroidManifest.xml b/LocationLib/AndroidManifest.xml index aa53294..47815ab 100644 --- a/LocationLib/AndroidManifest.xml +++ b/LocationLib/AndroidManifest.xml @@ -15,7 +15,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LocationLib/libs/.gitkeep b/LocationLib/libs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/LocationLib/project.properties b/LocationLib/project.properties index b15f120..390812c 100644 --- a/LocationLib/project.properties +++ b/LocationLib/project.properties @@ -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 + diff --git a/LocationLib/res/layout/base_map_fragment.xml b/LocationLib/res/layout/base_map_fragment.xml index 0c9c29a..7ac44da 100644 --- a/LocationLib/res/layout/base_map_fragment.xml +++ b/LocationLib/res/layout/base_map_fragment.xml @@ -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" /> 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 mPoints = new ArrayList(); - 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 mPoints = new ArrayList(); +//// 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 diff --git a/LocationLib/src/com/TwentyCodes/android/location/GeoPointLocationListener.java b/LocationLib/src/com/TwentyCodes/android/location/LatLngListener.java similarity index 83% rename from LocationLib/src/com/TwentyCodes/android/location/GeoPointLocationListener.java rename to LocationLib/src/com/TwentyCodes/android/location/LatLngListener.java index f432ae5..6c9f6f7 100644 --- a/LocationLib/src/com/TwentyCodes/android/location/GeoPointLocationListener.java +++ b/LocationLib/src/com/TwentyCodes/android/location/LatLngListener.java @@ -19,15 +19,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 @@ -44,5 +44,5 @@ public interface GeoPointLocationListener { * @param accuracy * @author ricky barrette */ - public void onLocationChanged(GeoPoint point, int accuracy); + public void onLocationChanged(LatLng point, int accuracy); } diff --git a/LocationLib/src/com/TwentyCodes/android/location/MidPoint.java b/LocationLib/src/com/TwentyCodes/android/location/MidPoint.java deleted file mode 100644 index a28b3a5..0000000 --- a/LocationLib/src/com/TwentyCodes/android/location/MidPoint.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * MidPoint.java - * @author ricky barrette - * @date Nov 30, 2010 - * - * Copyright 2012 Richard Barrette - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ -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); - } -} \ No newline at end of file diff --git a/LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java b/LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java index dcde417..5116153 100644 --- a/LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java +++ b/LocationLib/src/com/TwentyCodes/android/location/OnLocationSelectedListener.java @@ -19,7 +19,7 @@ */ 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 @@ -29,5 +29,5 @@ import com.google.android.maps.GeoPoint; */ public interface OnLocationSelectedListener { - public void onLocationSelected(GeoPoint point); + public void onLocationSelected(LatLng point); } \ No newline at end of file diff --git a/LocationLib/src/com/TwentyCodes/android/overlays/BaseUserOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/BaseUserOverlay.java index e35bfc1..b48bdd5 100644 --- a/LocationLib/src/com/TwentyCodes/android/overlays/BaseUserOverlay.java +++ b/LocationLib/src/com/TwentyCodes/android/overlays/BaseUserOverlay.java @@ -20,33 +20,24 @@ package com.TwentyCodes.android.overlays; import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Matrix; -import android.graphics.Paint; +import android.graphics.*; import android.graphics.Paint.Style; -import android.graphics.Point; -import android.graphics.RectF; 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.GeoUtils; +import com.TwentyCodes.android.location.LatLngListener; import com.TwentyCodes.android.location.R; +import com.google.android.gms.maps.model.LatLng; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; -import com.google.android.maps.Projection; /** * This class will be used to build user overlays * * @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 @@ -123,11 +114,11 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio private AnimationThread mAnimationThread; private float mBearing = 0; private int mAccuracy; - private GeoPoint mPoint; + private LatLng mPoint; 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; @@ -200,22 +191,22 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio */ @Override public void draw(Canvas canvas, final MapView mapView, final boolean shadow) { - if (isEnabled && mPoint != null) { - final Point center = new Point(); - final Point left = new Point(); - final Projection projection = mapView.getProjection(); - final GeoPoint leftGeo = GeoUtils.distanceFrom(mPoint, mAccuracy); - projection.toPixels(leftGeo, left); - projection.toPixels(mPoint, center); - canvas = drawAccuracyCircle(center, left, canvas); - canvas = drawUser(center, mBearing, canvas); - /* - * the following log is used to demonstrate if the leftGeo point is - * the correct - */ - if (Debug.DEBUG) - Log.d(TAG, GeoUtils.distanceKm(mPoint, leftGeo) * 1000 + "m"); - } +// if (isEnabled && mPoint != null) { +// final Point center = new Point(); +// final Point left = new Point(); +// final Projection projection = mapView.getProjection(); +// final LatLng leftGeo = GeoUtils.distanceFrom(mPoint, mAccuracy); +// projection.toPixels(leftGeo, left); +// projection.toPixels(mPoint, center); +// canvas = drawAccuracyCircle(center, left, canvas); +// canvas = drawUser(center, mBearing, canvas); +// /* +// * the following log is used to demonstrate if the leftGeo point is +// * the correct +// */ +// if (Debug.DEBUG) +// Log.d(TAG, GeoUtils.distanceKm(mPoint, leftGeo) * 1000 + "m"); +// } super.draw(canvas, mapView, shadow); } @@ -339,7 +330,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio * @return return the current destination * @author ricky barrette */ - public GeoPoint getDestination() { + public LatLng getDestination() { return mCompass.getDestination(); } @@ -359,7 +350,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio * @return * @author ricky barrette */ - public GeoPoint getUserLocation() { + public LatLng getUserLocation() { return mPoint; } @@ -375,14 +366,12 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio * called when the SkyHook location changes, this mthod is resposiable for * updating the overlay location and accuracy circle. (non-Javadoc) * - * @see com.TwentyCodes.android.SkyHook.GeoPointLocationListener.location.LocationListener#onLocationChanged(com.google.android.maps.GeoPoint, - * float) * @param point * @param accuracy * @author ricky barrette */ @Override - public void onLocationChanged(final GeoPoint point, final int accuracy) { + public void onLocationChanged(final LatLng point, final int accuracy) { if (mCompass != null) mCompass.setLocation(point); @@ -391,13 +380,13 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio * if this is the first fix set map center the users location, and zoom * to the max zoom level */ - if (point != null && isFistFix) { - mMapView.getController().setCenter(point); - mMapView.getController().setZoom(mMapView.getMaxZoomLevel() - 2); - if (mListener != null) - mListener.onFirstFix(true); - isFistFix = false; - } +// if (point != null && isFistFix) { +// mMapView.getController().setCenter(point); +// mMapView.getController().setZoom(mMapView.getMaxZoomLevel() - 2); +// if (mListener != null) +// mListener.onFirstFix(true); +// isFistFix = false; +// } // update the users point, and accuracy for the UI mPoint = point; @@ -406,8 +395,8 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio if (mListener != null) mListener.onLocationChanged(point, accuracy); - if (isFollowingUser) - panToUserIfOffMap(point); +// if (isFollowingUser) +// panToUserIfOffMap(point); } /** @@ -433,19 +422,19 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio */ private void panToUserIfOffMap(final GeoPoint user) { final GeoPoint center = mMapView.getMapCenter(); - final double distance = GeoUtils.distanceKm(center, user); - final double distanceLat = GeoUtils.distanceKm(center, new GeoPoint(center.getLatitudeE6() + mMapView.getLatitudeSpan() / 2, center.getLongitudeE6())); - final double distanceLon = GeoUtils.distanceKm(center, new GeoPoint(center.getLatitudeE6(), center.getLongitudeE6() + mMapView.getLongitudeSpan() / 2)); - - final double whichIsGreater = distanceLat > distanceLon ? distanceLat : distanceLon; - - /** - * if the user is one the map, keep them their else don't pan to user - * unless they pan pack to them - */ - if (!(distance > whichIsGreater)) - if (distance > distanceLat || distance > distanceLon) - mMapView.getController().animateTo(user); +// final double distance = GeoUtils.distanceKm(center, user); +// final double distanceLat = GeoUtils.distanceKm(center, new GeoPoint(center.getLatitudeE6() + mMapView.getLatitudeSpan() / 2, center.getLongitudeE6())); +// final double distanceLon = GeoUtils.distanceKm(center, new GeoPoint(center.getLatitudeE6(), center.getLongitudeE6() + mMapView.getLongitudeSpan() / 2)); +// +// final double whichIsGreater = distanceLat > distanceLon ? distanceLat : distanceLon; +// +// /** +// * if the user is one the map, keep them their else don't pan to user +// * unless they pan pack to them +// */ +// if (!(distance > whichIsGreater)) +// if (distance > distanceLat || distance > distanceLon) +// mMapView.getController().animateTo(user); } /** @@ -454,7 +443,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; @@ -488,7 +477,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio * * @author ricky barrette */ - public void setDestination(final GeoPoint destination) { + public void setDestination(final LatLng destination) { if (mCompass != null) mCompass.setDestination(destination); } diff --git a/LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java index ea8c1d1..17b4b9c 100644 --- a/LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java +++ b/LocationLib/src/com/TwentyCodes/android/overlays/CompasOverlay.java @@ -21,18 +21,13 @@ package com.TwentyCodes.android.overlays; import android.content.Context; import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.Point; +import android.graphics.*; import android.util.TypedValue; - import com.TwentyCodes.android.location.CompassSensor; import com.TwentyCodes.android.location.CompassSensor.CompassListener; import com.TwentyCodes.android.location.GeoUtils; import com.TwentyCodes.android.location.R; -import com.google.android.maps.GeoPoint; +import com.google.android.gms.maps.model.LatLng; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; @@ -46,8 +41,8 @@ public class CompasOverlay extends Overlay implements CompassListener { private float mBearing; private final Context mContext; - private GeoPoint mDestination; - private GeoPoint mLocation; + private LatLng mDestination; + private LatLng mLocation; private boolean isEnabled; private final CompassSensor mCompassSensor; private int mNeedleResId = R.drawable.needle_sm; @@ -75,7 +70,7 @@ public class CompasOverlay extends Overlay implements CompassListener { * @param destination * @author ricky barrette */ - public CompasOverlay(final Context context, final GeoPoint destination) { + public CompasOverlay(final Context context, final LatLng destination) { this(context); mDestination = destination; } @@ -93,7 +88,7 @@ public class CompasOverlay extends Overlay implements CompassListener { * dip * @author ricky barrette */ - public CompasOverlay(final Context context, final GeoPoint destination, final int needleResId, final int backgroundResId, final int x, final int y) { + public CompasOverlay(final Context context, final LatLng destination, final int needleResId, final int backgroundResId, final int x, final int y) { this(context, destination); mX = convertDipToPx(x); mY = convertDipToPx(y); @@ -118,7 +113,7 @@ public class CompasOverlay extends Overlay implements CompassListener { /** * Converts dip to px * - * @param dip + * @param i DIP * @return px * @author ricky barrette */ @@ -204,7 +199,7 @@ public class CompasOverlay extends Overlay implements CompassListener { * @return return the current destination * @author ricky barrette */ - public GeoPoint getDestination() { + public LatLng getDestination() { return mDestination; } @@ -212,7 +207,6 @@ public class CompasOverlay extends Overlay implements CompassListener { * Called from the compass Sensor to update the current bearing * (non-Javadoc) * - * @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float) * @author ricky barrette */ @Override @@ -230,7 +224,7 @@ public class CompasOverlay extends Overlay implements CompassListener { * @param destination * @author ricky barrette */ - public void setDestination(final GeoPoint destination) { + public void setDestination(final LatLng destination) { mDestination = destination; } @@ -254,7 +248,7 @@ public class CompasOverlay extends Overlay implements CompassListener { * @param location * @author ricky barrette */ - public void setLocation(final GeoPoint location) { + public void setLocation(final LatLng location) { mLocation = location; } diff --git a/LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java b/LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java deleted file mode 100644 index dee412f..0000000 --- a/LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java +++ /dev/null @@ -1,182 +0,0 @@ -/** - * RadiusOverlay.java - * @author ricky barrette - * - * Copyright 2012 Richard Barrette - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -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; - -/** - * This class will used to draw a radius of a specified size in a specified - * location, then inserted into an overlay list to be displayed a map - * - * @author ricky barrette - */ -public class RadiusOverlay extends Overlay { - - public OverlayItem mOverlayItem; - private GeoPoint mPoint; - private float mRadius = 0; - private int mColor = Color.GREEN; - private GeoPoint mRadiusPoint; - private OnLocationSelectedListener mListener; - - /** - * Creates a new RadiusOverlay - * - * @author ricky barrette - */ - public RadiusOverlay() { - } - - /** - * Creates a new RadiusOverlay object that can be inserted into an overlay - * list. - * - * @param point - * center of radius geopoint - * @param radius - * radius in meters - * @param color - * 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); - } - } - - /** - * @return the selected location - * @author ricky barrette - */ - public GeoPoint getLocation() { - return mPoint; - } - - 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); - } - - /** - * @param color - * @author ricky barrette - */ - public void setColor(final int color) { - mColor = color; - } - - /** - * @param location - * @author ricky barrette - */ - public void setLocation(final GeoPoint location) { - mPoint = location; - } - - public void setLocationSelectedListener(final OnLocationSelectedListener listener) { - mListener = listener; - } - - /** - * @param radius - * in meters - * @author ricky barrette - * @param radius - */ - public void setRadius(final int radius) { - mRadius = radius; - } -} \ No newline at end of file