Merge branch 'v3'
Conflicts: LocationLib/libs/android-support-v4-r11-googlemaps.jar LocationLib/src/com/TwentyCodes/android/fragments/BaseMapFragment.java LocationLib/src/com/TwentyCodes/android/location/MidPoint.java LocationLib/src/com/TwentyCodes/android/overlays/RadiusOverlay.java
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
34
LocationLib/LocationLib.iml
Normal file
34
LocationLib/LocationLib.iml
Normal 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>
|
||||
|
||||
0
LocationLib/libs/.gitkeep
Normal file
0
LocationLib/libs/.gitkeep
Normal 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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
/**
|
||||
* MapFragment.java
|
||||
* @date Jan 7, 2012
|
||||
* @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.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);
|
||||
}
|
||||
}
|
||||
@@ -19,15 +19,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
|
||||
@@ -104,7 +103,6 @@ public class DirectionsListFragment extends ListFragment {
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see android.support.v4.app.Fragment#onStart()
|
||||
*/
|
||||
@Override
|
||||
public void onStart() {
|
||||
@@ -124,7 +122,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
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
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.maps.GeoPoint;
|
||||
import com.google.android.gms.maps.MapFragment;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
|
||||
/**
|
||||
* This is a MapFragment that maintains the UserOverlay
|
||||
@@ -32,10 +33,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;
|
||||
|
||||
/**
|
||||
@@ -61,7 +62,7 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
||||
* @return return the current destination
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getDestination() {
|
||||
public LatLng getDestination() {
|
||||
return mUserOverlay.getDestination();
|
||||
}
|
||||
|
||||
@@ -69,14 +70,13 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
||||
* @return the users current location
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public GeoPoint getUserLocation() {
|
||||
public LatLng getUserLocation() {
|
||||
return mUserOverlay.getUserLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the compass is updated (non-Javadoc)
|
||||
*
|
||||
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
|
||||
*/
|
||||
@Override
|
||||
public void onCompassUpdate(final float bearing) {
|
||||
@@ -86,8 +86,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,17 +96,15 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public void onLocationChanged(final GeoPoint point, final int accuracy) {
|
||||
if (mGeoPointLocationListener != null)
|
||||
mGeoPointLocationListener.onLocationChanged(point, accuracy);
|
||||
public void onLocationChanged(final LatLng point, final int 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);
|
||||
@@ -120,26 +118,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,10 +144,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
|
||||
@@ -178,7 +174,7 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
||||
* @param destination
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void setDestination(final GeoPoint destination) {
|
||||
public void setDestination(final LatLng destination) {
|
||||
mUserOverlay.setDestination(destination);
|
||||
}
|
||||
|
||||
@@ -186,7 +182,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;
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,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
|
||||
@@ -39,7 +38,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;
|
||||
|
||||
@@ -71,7 +70,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) {
|
||||
@@ -105,7 +104,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,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
|
||||
@@ -71,18 +66,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +91,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;
|
||||
@@ -116,24 +107,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 =
|
||||
@@ -149,7 +140,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
|
||||
*
|
||||
@@ -159,8 +150,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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,16 +185,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,71 +241,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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user