地图依赖重构
This commit is contained in:
@@ -6,12 +6,13 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
@@ -97,11 +98,34 @@ public class MyLocationUtil {
|
||||
if (res == null) {
|
||||
throw new IllegalArgumentException("inflate myLocation bitmap can not be null!");
|
||||
}
|
||||
View root =
|
||||
LayoutInflater.from(context).inflate(R.layout.module_common_my_location, null, false);
|
||||
ImageView iv =
|
||||
root.findViewById(R.id.module_map_amap_my_location_iv);
|
||||
View root = LayoutInflater.from(context).inflate(R.layout.module_common_my_location, null, false);
|
||||
ImageView iv = root.findViewById(R.id.module_map_amap_my_location_iv);
|
||||
iv.setImageBitmap(res);
|
||||
return BitmapDescriptorFactory.fromView(root).getBitmap();
|
||||
return fromView(root);
|
||||
}
|
||||
|
||||
|
||||
private static Bitmap fromView( View view ) {
|
||||
view.setDrawingCacheEnabled( true );
|
||||
processChildView( view );
|
||||
view.destroyDrawingCache();
|
||||
view.measure( View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ), View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ) );
|
||||
view.layout( 0, 0, view.getMeasuredWidth(), view.getMeasuredHeight() );
|
||||
Bitmap bitmap = null;
|
||||
return ( bitmap = view.getDrawingCache() ) != null ? bitmap.copy( Bitmap.Config.ARGB_8888, false ) : null;
|
||||
}
|
||||
|
||||
private static void processChildView( View view ) {
|
||||
if ( !( view instanceof ViewGroup ) ) {
|
||||
if ( view instanceof TextView ) {
|
||||
( ( TextView ) view ).setHorizontallyScrolling( false );
|
||||
}
|
||||
|
||||
} else {
|
||||
for ( int var1 = 0; var1 < ( ( ViewGroup ) view ).getChildCount(); ++var1 ) {
|
||||
processChildView( ( ( ViewGroup ) view ).getChildAt( var1 ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.mogo.module.common.utils;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
*/
|
||||
@@ -13,7 +11,6 @@ public class CoordinateUtils {
|
||||
/**
|
||||
* 手机GPS坐标转火星坐标
|
||||
*
|
||||
* @param wgLoc
|
||||
* @return
|
||||
*/
|
||||
public static double[] transformFromWGSToGCJ( double lat, double lon ) {
|
||||
@@ -36,32 +33,6 @@ public class CoordinateUtils {
|
||||
return new double[]{lat + dLat, lon + dLon};
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机GPS坐标转火星坐标
|
||||
*
|
||||
* @param wgLoc
|
||||
* @return
|
||||
*/
|
||||
public static LatLng transformFromWGSToGCJ( LatLng wgLoc ) {
|
||||
|
||||
//如果在国外,则默认不进行转换
|
||||
if ( outOfChina( wgLoc.latitude, wgLoc.longitude ) ) {
|
||||
return new LatLng( wgLoc.latitude, wgLoc.longitude );
|
||||
}
|
||||
double dLat = transformLat( wgLoc.longitude - 105.0,
|
||||
wgLoc.latitude - 35.0 );
|
||||
double dLon = transformLon( wgLoc.longitude - 105.0,
|
||||
wgLoc.latitude - 35.0 );
|
||||
double radLat = wgLoc.latitude / 180.0 * Math.PI;
|
||||
double magic = Math.sin( radLat );
|
||||
magic = 1 - ee * magic * magic;
|
||||
double sqrtMagic = Math.sqrt( magic );
|
||||
dLat = ( dLat * 180.0 ) / ( ( a * ( 1 - ee ) ) / ( magic * sqrtMagic ) * Math.PI );
|
||||
dLon = ( dLon * 180.0 ) / ( a / sqrtMagic * Math.cos( radLat ) * Math.PI );
|
||||
|
||||
return new LatLng( wgLoc.latitude + dLat, wgLoc.longitude + dLon );
|
||||
}
|
||||
|
||||
public static double transformLat( double x, double y ) {
|
||||
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y
|
||||
+ 0.2 * Math.sqrt( x > 0 ? x : -x );
|
||||
|
||||
Reference in New Issue
Block a user