更新搜索页面
This commit is contained in:
@@ -1,131 +0,0 @@
|
||||
package com.mogo.module.map.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationClientOption;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class AMapLocationManager {
|
||||
|
||||
private static final String TAG = "AMapLocationManager";
|
||||
|
||||
private static final Set< AMapLocationListener > mLocationChangeListeners = new HashSet<>();
|
||||
private static final InternalLocationListener mInternalLocationListener = new InternalLocationListener();
|
||||
|
||||
private AMapLocationClient mLocationClient;
|
||||
|
||||
private static AMapLocation sLastKnowLocation = null;
|
||||
|
||||
private static volatile AMapLocationManager sInstance;
|
||||
|
||||
public static AMapLocationManager getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( AMapLocationManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new AMapLocationManager( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
stop();
|
||||
mLocationChangeListeners.clear();
|
||||
mLocationClient = null;
|
||||
sLastKnowLocation = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private AMapLocationManager( Context context ) {
|
||||
if ( context == null ) {
|
||||
throw new NullPointerException( "context can't be null." );
|
||||
}
|
||||
mLocationClient = new AMapLocationClient( context.getApplicationContext() );
|
||||
mLocationClient.setLocationListener( mInternalLocationListener );
|
||||
}
|
||||
|
||||
private void setLocationOptions( long locateInterval ) {
|
||||
AMapLocationClientOption option = new AMapLocationClientOption();
|
||||
option.setLocationMode( AMapLocationClientOption.AMapLocationMode.Hight_Accuracy );
|
||||
option.setNeedAddress( true );
|
||||
option.setInterval( locateInterval );
|
||||
if ( mLocationClient != null ) {
|
||||
mLocationClient.setLocationOption( option );
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
start( 2000L );
|
||||
}
|
||||
|
||||
public synchronized void start( long locateInterval ) {
|
||||
if ( mLocationClient != null && mLocationClient.isStarted() ) {
|
||||
stop();
|
||||
}
|
||||
setLocationOptions( locateInterval );
|
||||
mLocationClient.startLocation();
|
||||
Log.d( TAG, "start location, location interval is " + locateInterval );
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
if ( mLocationClient != null ) {
|
||||
mLocationClient.stopLocation();
|
||||
}
|
||||
Log.d( TAG, "stop location" );
|
||||
}
|
||||
|
||||
public static AMapLocation getAMapLastKnowLocation() {
|
||||
return sLastKnowLocation;
|
||||
}
|
||||
|
||||
public static LatLng getLastKnowPoint() {
|
||||
final AMapLocation location = getAMapLastKnowLocation();
|
||||
if ( location != null ) {
|
||||
return new LatLng( location.getLatitude(), location.getLongitude() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addLocationListener( AMapLocationListener listener ) {
|
||||
if ( listener != null ) {
|
||||
synchronized ( mLocationChangeListeners ) {
|
||||
mLocationChangeListeners.add( listener );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLocationListener( AMapLocationListener listener ) {
|
||||
synchronized ( mLocationChangeListeners ) {
|
||||
mLocationChangeListeners.remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位SDK监听函数
|
||||
*/
|
||||
private static class InternalLocationListener implements AMapLocationListener {
|
||||
@Override
|
||||
public void onLocationChanged( AMapLocation aMapLocation ) {
|
||||
if ( aMapLocation == null ||
|
||||
aMapLocation.getLatitude() == 0.0D ||
|
||||
aMapLocation.getLongitude() == 0.0D ) {
|
||||
return;
|
||||
}
|
||||
sLastKnowLocation = aMapLocation.clone();
|
||||
synchronized ( mLocationChangeListeners ) {
|
||||
Iterator iterator = mLocationChangeListeners.iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
AMapLocationListener listener = ( AMapLocationListener ) iterator.next();
|
||||
listener.onLocationChanged( sLastKnowLocation );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.mogo.module.map.location;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-09-27
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class LocationUtils {
|
||||
|
||||
public static float bearing( double lat1, double lon1, double lat2, double lon2 ) {
|
||||
|
||||
double longitude1 = lon1;
|
||||
double longitude2 = lon2;
|
||||
double latitude1 = Math.toRadians( lat1 );
|
||||
double latitude2 = Math.toRadians( lat2 );
|
||||
double longDiff = Math.toRadians( longitude2 - longitude1 );
|
||||
double y = Math.sin( longDiff ) * Math.cos( latitude2 );
|
||||
double x = Math.cos( latitude1 ) * Math.sin( latitude2 ) - Math.sin( latitude1 ) * Math.cos( latitude2 ) * Math
|
||||
.cos( longDiff );
|
||||
|
||||
double result = ( Math.toDegrees( Math.atan2( y, x ) ) + 360 ) % 360;
|
||||
if ( ( ( int ) result ) == ( ( int ) ( result + 0.5 ) ) ) {
|
||||
return ( ( int ) result );
|
||||
} else {
|
||||
return ( ( int ) result ) + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.mogo.module.map.location;
|
||||
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-10-17
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MyLocationUtils {
|
||||
|
||||
public static final long INTERVAL_FAST_SPEED = 2_000L;
|
||||
public static final long INTERVAL_MIDDLE_SPEED = 2_000L;
|
||||
public static final long INTERVAL_SLOW_SPEED = 10_000L;
|
||||
|
||||
/**
|
||||
* 前台快速定位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MyLocationStyle wrapperAsFast( MyLocationStyle style ) {
|
||||
if ( style != null ) {
|
||||
style.interval( INTERVAL_FAST_SPEED );
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台慢速定位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MyLocationStyle wrapperAsMiddleSpeed( MyLocationStyle style ) {
|
||||
if ( style != null ) {
|
||||
style.interval( INTERVAL_MIDDLE_SPEED );
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台慢速定位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MyLocationStyle wrapperAsSlow( MyLocationStyle style ) {
|
||||
if ( style != null ) {
|
||||
style.interval( INTERVAL_SLOW_SPEED );
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user