Import to intelij, started updating to use maps v2
This commit is contained in:
@@ -4,5 +4,6 @@
|
|||||||
<classpathentry kind="src" path="gen"/>
|
<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.ANDROID_FRAMEWORK"/>
|
||||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
<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"/>
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="7"
|
android:minSdkVersion="11"
|
||||||
android:targetSdkVersion="16" />
|
android:targetSdkVersion="16" />
|
||||||
|
|
||||||
<uses-feature
|
<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
Binary file not shown.
Binary file not shown.
@@ -9,4 +9,6 @@
|
|||||||
|
|
||||||
android.library=true
|
android.library=true
|
||||||
# Project target.
|
# 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:id="@+id/mapview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:apiKey="0rKmsWMM0D-LWOndcfwrmW-S0OXlnQl2SJCMeTg" />
|
android:apiKey="0rKmsWMM0D-IRAEgcSZEqwZCs_8AUwxjYjj0bnA" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/mapProgressBar"
|
android:id="@+id/mapProgressBar"
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,15 +6,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.fragments;
|
package com.TwentyCodes.android.fragments;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.support.v4.app.ListFragment;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.TwentyCodes.android.overlays.DirectionsOverlay;
|
import com.TwentyCodes.android.overlays.DirectionsOverlay;
|
||||||
import com.google.android.maps.GeoPoint;
|
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
|
* 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)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see android.support.v4.app.Fragment#onStart()
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
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
|
* @param text
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
package com.TwentyCodes.android.fragments;
|
package com.TwentyCodes.android.fragments;
|
||||||
|
|
||||||
import com.TwentyCodes.android.location.CompassSensor.CompassListener;
|
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.location.MapView;
|
||||||
import com.TwentyCodes.android.overlays.UserOverlay;
|
import com.TwentyCodes.android.overlays.UserOverlay;
|
||||||
|
import com.google.android.gms.maps.MapFragment;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,10 +20,10 @@ import com.google.android.maps.GeoPoint;
|
|||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointLocationListener, CompassListener {
|
public class UserOverlayMapFragment extends MapFragment implements LatLngListener, CompassListener {
|
||||||
|
|
||||||
private UserOverlay mUserOverlay;
|
private UserOverlay mUserOverlay;
|
||||||
private GeoPointLocationListener mGeoPointLocationListener;
|
private LatLngListener mLatLngListener;
|
||||||
private CompassListener mCompassListener;
|
private CompassListener mCompassListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +64,6 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
|||||||
/**
|
/**
|
||||||
* Called when the compass is updated (non-Javadoc)
|
* Called when the compass is updated (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see com.TwentyCodes.android.location.CompassListener#onCompassUpdate(float)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCompassUpdate(final float bearing) {
|
public void onCompassUpdate(final float bearing) {
|
||||||
@@ -73,8 +73,8 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFirstFix(final boolean isFistFix) {
|
public void onFirstFix(final boolean isFistFix) {
|
||||||
if (mGeoPointLocationListener != null)
|
if (mLatLngListener != null)
|
||||||
mGeoPointLocationListener.onFirstFix(isFistFix);
|
mLatLngListener.onFirstFix(isFistFix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,16 +84,14 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final GeoPoint point, final int accuracy) {
|
public void onLocationChanged(final GeoPoint point, final int accuracy) {
|
||||||
if (mGeoPointLocationListener != null)
|
if (mLatLngListener != null)
|
||||||
mGeoPointLocationListener.onLocationChanged(point, accuracy);
|
mLatLngListener.onLocationChanged(point, accuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onMapViewCreate(com.TwentyCodes.android.location.MapView)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void onMapViewCreate(final MapView map) {
|
public void onMapViewCreate(final MapView map) {
|
||||||
mUserOverlay = new UserOverlay(map, getActivity().getApplicationContext());
|
mUserOverlay = new UserOverlay(map, getActivity().getApplicationContext());
|
||||||
mUserOverlay.registerListener(this);
|
mUserOverlay.registerListener(this);
|
||||||
@@ -107,26 +105,24 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
|||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onPause()
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mUserOverlay.disableMyLocation();
|
mUserOverlay.disableMyLocation();
|
||||||
removeOverlay(mUserOverlay);
|
// removeOverlay(mUserOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see com.TwentyCodes.android.fragments.BaseMapFragment#onResume()
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (mUserOverlay != null) {
|
if (mUserOverlay != null) {
|
||||||
mUserOverlay.enableMyLocation();
|
mUserOverlay.enableMyLocation();
|
||||||
addOverlay(mUserOverlay);
|
// addOverlay(mUserOverlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,10 +131,10 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
|||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void reorderOverlays() {
|
// public void reorderOverlays() {
|
||||||
getMap().getOverlays().remove(mUserOverlay);
|
// getMap().getOverlays().remove(mUserOverlay);
|
||||||
getMap().getOverlays().add(mUserOverlay);
|
// getMap().getOverlays().add(mUserOverlay);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param needleResId
|
* @param needleResId
|
||||||
@@ -173,7 +169,7 @@ public class UserOverlayMapFragment extends BaseMapFragment implements GeoPointL
|
|||||||
* @param listener
|
* @param listener
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setGeoPointLocationListener(final GeoPointLocationListener listener) {
|
public void setGeoPointLocationListener(final LatLngListener listener) {
|
||||||
mGeoPointLocationListener = listener;
|
mLatLngListener = listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,9 +13,8 @@ import android.location.LocationListener;
|
|||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.TwentyCodes.android.debug.Debug;
|
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
|
* 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 static final String TAG = "AndroidGPS";
|
||||||
private final LocationManager mLocationManager;
|
private final LocationManager mLocationManager;
|
||||||
private GeoPointLocationListener mListener;
|
private LatLngListener mListener;
|
||||||
private LocationListener mLocationListener;
|
private LocationListener mLocationListener;
|
||||||
private boolean isFirstFix;
|
private boolean isFirstFix;
|
||||||
|
|
||||||
@@ -59,7 +58,7 @@ public class AndroidGPS implements LocationListener {
|
|||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void enableLocationUpdates(final GeoPointLocationListener listener) {
|
public void enableLocationUpdates(final LatLngListener listener) {
|
||||||
if (Debug.DEBUG)
|
if (Debug.DEBUG)
|
||||||
Log.d(TAG, "enableLocationUpdates()");
|
Log.d(TAG, "enableLocationUpdates()");
|
||||||
if (mListener == null) {
|
if (mListener == null) {
|
||||||
@@ -93,7 +92,7 @@ public class AndroidGPS implements LocationListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final Location location) {
|
public void onLocationChanged(final Location location) {
|
||||||
if (mListener != null) {
|
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);
|
mListener.onFirstFix(isFirstFix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.location;
|
package com.TwentyCodes.android.location;
|
||||||
|
|
||||||
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
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
|
* This class contains common tools for computing common geological problems
|
||||||
@@ -70,18 +65,14 @@ public class GeoUtils {
|
|||||||
* degrees East of true north
|
* degrees East of true north
|
||||||
*
|
*
|
||||||
* @param p1
|
* @param p1
|
||||||
* source geopoint
|
* source LatLng
|
||||||
* @param p2
|
* @param p2
|
||||||
* destination geopoint
|
* destination LatLng
|
||||||
* @return the bearing of p2 in relationship from p1 in degrees East
|
* @return the bearing of p2 in relationship from p1 in degrees East
|
||||||
* @author Google Inc.
|
* @author Google Inc.
|
||||||
*/
|
*/
|
||||||
public static Double bearing(final GeoPoint p1, final GeoPoint p2) {
|
public static Double bearing(final LatLng p1, final LatLng p2) {
|
||||||
final double lat1 = p1.getLatitudeE6() / MILLION;
|
return bearing(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
|
||||||
final double lon1 = p1.getLongitudeE6() / MILLION;
|
|
||||||
final double lat2 = p2.getLatitudeE6() / MILLION;
|
|
||||||
final double lon2 = p2.getLongitudeE6() / MILLION;
|
|
||||||
return bearing(lat1, lon1, lat2, lon2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +90,7 @@ public class GeoUtils {
|
|||||||
* @return Degrees East of dest location
|
* @return Degrees East of dest location
|
||||||
* @author ricky barrette
|
* @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)
|
if (user == null || dest == null)
|
||||||
return bearing;
|
return bearing;
|
||||||
@@ -115,24 +106,24 @@ public class GeoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates a geopoint x meters away of the geopoint supplied. The new
|
* Calculates a LatLng x meters away of the LatLng supplied. The new
|
||||||
* geopoint shares the same latitude as geopoint point, this way they are on
|
* LatLng shares the same latitude as LatLng point, this way they are on
|
||||||
* the same latitude arc.
|
* the same latitude arc.
|
||||||
*
|
*
|
||||||
* @param point
|
* @param point
|
||||||
* central geopoint
|
* central LatLng
|
||||||
* @param distance
|
* @param distance
|
||||||
* in meters from the geopoint
|
* in meters from the LatLng
|
||||||
* @return geopoint that is x meters away from the geopoint supplied
|
* @return LatLng that is x meters away from the LatLng supplied
|
||||||
* @author ricky barrette
|
* @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
|
// convert meters into kilometers
|
||||||
distance = distance / 1000;
|
distance = distance / 1000;
|
||||||
|
|
||||||
// convert lat and lon of geopoint to radians
|
// convert lat and lon of LatLng to radians
|
||||||
final double lat1Rad = Math.toRadians(point.getLatitudeE6() / 1e6);
|
final double lat1Rad = Math.toRadians(point.latitude);
|
||||||
final double lon1Rad = Math.toRadians(point.getLongitudeE6() / 1e6);
|
final double lon1Rad = Math.toRadians(point.longitude);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* kilometers =
|
* kilometers =
|
||||||
@@ -148,7 +139,7 @@ public class GeoUtils {
|
|||||||
* NOTE: sec(x) = 1/cos(x)
|
* NOTE: sec(x) = 1/cos(x)
|
||||||
*
|
*
|
||||||
* NOTE: that lat2Rad is = lat1Rad because we want to keep the new
|
* 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
|
* variable for lat2Rad, and simply inputed lat1Rad in place of lat2Rad
|
||||||
* in the equation
|
* 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));
|
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 a LatLng that is x meters away from the LatLng supplied
|
||||||
return new GeoPoint(point.getLatitudeE6(), (int) (Math.toDegrees(lon2Rad) * 1e6));
|
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
|
* @return the distance between to p1 and p2
|
||||||
* @author Google Inc.
|
* @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 we are handed a null, return -1 so we don't break
|
||||||
if (p1 == null || p2 == null)
|
if (p1 == null || p2 == null)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
final double lat1 = p1.getLatitudeE6() / MILLION;
|
return distanceKm(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
|
||||||
final double lon1 = p1.getLongitudeE6() / MILLION;
|
|
||||||
final double lat2 = p2.getLatitudeE6() / MILLION;
|
|
||||||
final double lon2 = p2.getLongitudeE6() / MILLION;
|
|
||||||
return distanceKm(lat1, lon1, lat2, lon2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,71 +240,80 @@ public class GeoUtils {
|
|||||||
* @return true if the circles intersect
|
* @return true if the circles intersect
|
||||||
* @author ricky barrette
|
* @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) {
|
final float fudgeFactor) {
|
||||||
if (accuracyRadius + locationRadius - fudgeFactor > distanceKm(locationPoint, userPoint))
|
if (accuracyRadius + locationRadius - fudgeFactor > distanceKm(locationPoint, userPoint))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* determines when the specified point is off the map
|
// * determines when the specified point is off the map
|
||||||
*
|
// *
|
||||||
* @param point
|
// * @param point
|
||||||
* @return true is the point is off the map
|
// * @return true is the point is off the map
|
||||||
* @author ricky barrette
|
// * @author ricky barrette
|
||||||
*/
|
// */
|
||||||
public static boolean isPointOffMap(final MapView map, final GeoPoint point) {
|
// public static boolean isPointOffMap(final GoogleMap map, final LatLng point) {
|
||||||
if (map == null)
|
//
|
||||||
return false;
|
// VisibleRegion vr = map.getProjection().getVisibleRegion();
|
||||||
if (point == null)
|
// double left = vr.latLngBounds.southwest.longitude;
|
||||||
return false;
|
// double top = vr.latLngBounds.northeast.latitude;
|
||||||
final GeoPoint center = map.getMapCenter();
|
// double right = vr.latLngBounds.northeast.longitude;
|
||||||
final double distance = GeoUtils.distanceKm(center, point);
|
// double bottom = vr.latLngBounds.southwest.latitude;
|
||||||
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 (map == null)
|
||||||
if (distance > distanceLat || distance > distanceLon)
|
// return false;
|
||||||
return true;
|
// if (point == null)
|
||||||
return false;
|
// 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));
|
||||||
* computes a geopoint the is the central geopoint between p1 and p1
|
// final double distanceLon = GeoUtils.distanceKm(center, new LatLng(center.latitude, center.longitude + map.getLongitudeSpan() / 2));
|
||||||
*
|
// if (distance > distanceLat || distance > distanceLon)
|
||||||
* @param p1
|
// return true;
|
||||||
* first geopoint
|
// return false;
|
||||||
* @param p2
|
//
|
||||||
* second geopoint
|
// return map.getProjection().toScreenLocation()
|
||||||
* @return a MidPoint object
|
// }
|
||||||
* @author ricky barrette
|
//
|
||||||
*/
|
// /**
|
||||||
public static MidPoint midPoint(final GeoPoint p1, final GeoPoint p2) {
|
// * computes a LatLng the is the central LatLng between p1 and p1
|
||||||
int minLatitude = (int) (+81 * 1E6);
|
// *
|
||||||
int maxLatitude = (int) (-81 * 1E6);
|
// * @param p1
|
||||||
int minLongitude = (int) (+181 * 1E6);
|
// * first LatLng
|
||||||
int maxLongitude = (int) (-181 * 1E6);
|
// * @param p2
|
||||||
final List<Point> mPoints = new ArrayList<Point>();
|
// * second LatLng
|
||||||
int latitude = p1.getLatitudeE6();
|
// * @return a MidPoint object
|
||||||
int longitude = p1.getLongitudeE6();
|
// * @author ricky barrette
|
||||||
if (latitude != 0 && longitude != 0) {
|
// */
|
||||||
minLatitude = minLatitude > latitude ? latitude : minLatitude;
|
// public static MidPoint midpoint(final LatLng p1, final LatLng p2) {
|
||||||
maxLatitude = maxLatitude < latitude ? latitude : maxLatitude;
|
//// double minLatitude = +81 * 1E6;
|
||||||
minLongitude = minLongitude > longitude ? longitude : minLongitude;
|
//// double maxLatitude = -81 * 1E6;
|
||||||
maxLongitude = maxLongitude < longitude ? longitude : maxLongitude;
|
//// double minLongitude = +181 * 1E6;
|
||||||
mPoints.add(new Point(latitude, longitude));
|
//// double maxLongitude = -181 * 1E6;
|
||||||
}
|
//// final List<Point> mPoints = new ArrayList<Point>();
|
||||||
|
//// if (p1.latitude != 0 && p1.longitude != 0) {
|
||||||
latitude = p2.getLatitudeE6();
|
//// minLatitude = minLatitude > p1.latitude ? p1.latitude : minLatitude;
|
||||||
longitude = p2.getLongitudeE6();
|
//// maxLatitude = maxLatitude < p1.latitude ? p1.latitude : maxLatitude;
|
||||||
if (latitude != 0 && longitude != 0) {
|
//// minLongitude = minLongitude > p1.longitude ? p1.longitude : minLongitude;
|
||||||
minLatitude = minLatitude > latitude ? latitude : minLatitude;
|
//// maxLongitude = maxLongitude < p1.longitude ? p1.longitude : maxLongitude;
|
||||||
maxLatitude = maxLatitude < latitude ? latitude : maxLatitude;
|
//// mPoints.add(new Point(p1.latitude, p1.longitude));
|
||||||
minLongitude = minLongitude > longitude ? longitude : minLongitude;
|
//// }
|
||||||
maxLongitude = maxLongitude < longitude ? longitude : maxLongitude;
|
////
|
||||||
mPoints.add(new Point(latitude, longitude));
|
//// if (p2.latitude != 0 && p2.longitude != 0) {
|
||||||
}
|
//// minLatitude = minLatitude > p2.latitude ? p2.latitude : minLatitude;
|
||||||
return new MidPoint(new GeoPoint((maxLatitude + minLatitude) / 2, (maxLongitude + minLongitude) / 2), minLatitude, minLongitude, maxLatitude, maxLongitude);
|
//// 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
|
* converts radians to bearing
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.location;
|
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
|
* the application
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public interface GeoPointLocationListener {
|
public interface LatLngListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when first fix is aquired
|
* Called when first fix is aquired
|
||||||
@@ -30,5 +30,5 @@ public interface GeoPointLocationListener {
|
|||||||
* @param accuracy
|
* @param accuracy
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void onLocationChanged(GeoPoint point, int accuracy);
|
public void onLocationChanged(LatLng point, int accuracy);
|
||||||
}
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.TwentyCodes.android.location;
|
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
|
* 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 interface OnLocationSelectedListener {
|
||||||
|
|
||||||
public void onLocationSelected(GeoPoint point);
|
public void onLocationSelected(LatLng point);
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.TwentyCodes.android.debug.Debug;
|
import com.TwentyCodes.android.debug.Debug;
|
||||||
import com.TwentyCodes.android.location.CompassSensor.CompassListener;
|
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.GeoUtils;
|
||||||
import com.TwentyCodes.android.location.R;
|
import com.TwentyCodes.android.location.R;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
@@ -33,7 +33,7 @@ import com.google.android.maps.Projection;
|
|||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @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
|
* 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 Context mContext;
|
||||||
private final MapView mMapView;
|
private final MapView mMapView;
|
||||||
private boolean isFistFix = true;
|
private boolean isFistFix = true;
|
||||||
private GeoPointLocationListener mListener;
|
private LatLngListener mListener;
|
||||||
public boolean isFollowingUser = true;
|
public boolean isFollowingUser = true;
|
||||||
private final CompasOverlay mCompass;
|
private final CompasOverlay mCompass;
|
||||||
private boolean isCompassEnabled;
|
private boolean isCompassEnabled;
|
||||||
@@ -441,7 +441,7 @@ public abstract class BaseUserOverlay extends Overlay implements GeoPointLocatio
|
|||||||
* @param listener
|
* @param listener
|
||||||
* @author Ricky Barrette
|
* @author Ricky Barrette
|
||||||
*/
|
*/
|
||||||
public void registerListener(final GeoPointLocationListener listener) {
|
public void registerListener(final LatLngListener listener) {
|
||||||
Log.d(TAG, "registerListener()");
|
Log.d(TAG, "registerListener()");
|
||||||
if (mListener == null)
|
if (mListener == null)
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
|
|||||||
@@ -5,20 +5,9 @@
|
|||||||
|
|
||||||
package com.TwentyCodes.android.overlays;
|
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.TwentyCodes.android.location.OnLocationSelectedListener;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.gms.maps.model.CircleOptions;
|
||||||
import com.google.android.maps.MapView;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
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
|
* 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
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class RadiusOverlay extends Overlay {
|
public class RadiusOverlay {
|
||||||
|
|
||||||
public OverlayItem mOverlayItem;
|
private final CircleOptions mCircleOptions;
|
||||||
private GeoPoint mPoint;
|
|
||||||
private float mRadius = 0;
|
|
||||||
private int mColor = Color.GREEN;
|
|
||||||
private GeoPoint mRadiusPoint;
|
|
||||||
private OnLocationSelectedListener mListener;
|
private OnLocationSelectedListener mListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,6 +26,7 @@ public class RadiusOverlay extends Overlay {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public RadiusOverlay() {
|
public RadiusOverlay() {
|
||||||
|
mCircleOptions = new CircleOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,101 +41,48 @@ public class RadiusOverlay extends Overlay {
|
|||||||
* desired color of the radius from Color API
|
* desired color of the radius from Color API
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public RadiusOverlay(final GeoPoint point, final float radius, final int color) {
|
public RadiusOverlay(final LatLng point, final double radius, final int color) {
|
||||||
mPoint = point;
|
mCircleOptions = new CircleOptions();
|
||||||
mRadius = radius;
|
mCircleOptions.center(point);
|
||||||
mColor = color;
|
mCircleOptions.radius(radius);
|
||||||
}
|
mCircleOptions.fillColor(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
|
* @return the selected location
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public GeoPoint getLocation() {
|
public LatLng getLocation() {
|
||||||
return mPoint;
|
return mCircleOptions.getCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getZoomLevel() {
|
public int getZoomLevel() {
|
||||||
// GeoUtils.GeoUtils.distanceFrom(mPoint , mRadius)
|
// GeoUtils.GeoUtils.distanceFrom(mPoint , mRadius)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public boolean onTap(final GeoPoint p, final MapView mapView) {
|
// public boolean onTap(final GeoPoint p, final MapView mapView) {
|
||||||
mPoint = p;
|
// mPoint = p;
|
||||||
if (mListener != null)
|
// if (mListener != null)
|
||||||
mListener.onLocationSelected(p);
|
// mListener.onLocationSelected(p);
|
||||||
return super.onTap(p, mapView);
|
// return super.onTap(p, mapView);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param color
|
* @param color
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setColor(final int color) {
|
public void setColor(final int color) {
|
||||||
mColor = color;
|
mCircleOptions.fillColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param location
|
* @param location
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void setLocation(final GeoPoint location) {
|
public void setLocation(final LatLng location) {
|
||||||
mPoint = location;
|
mCircleOptions.center(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationSelectedListener(final OnLocationSelectedListener listener) {
|
public void setLocationSelectedListener(final OnLocationSelectedListener listener) {
|
||||||
@@ -162,7 +95,15 @@ public class RadiusOverlay extends Overlay {
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @param radius
|
* @param radius
|
||||||
*/
|
*/
|
||||||
public void setRadius(final int radius) {
|
public void setRadius(final double radius) {
|
||||||
mRadius = radius;
|
mCircleOptions.radius(radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CircleOptions getCircleOptions(){
|
||||||
|
return mCircleOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user