Commit dbeef15f authored by Administrator's avatar Administrator

基本测试通过

parent 1eca0652
......@@ -158,6 +158,14 @@ public class XPosedPlugin implements IRposedHookLoadPackage {
Location location = (Location) obj;
location.setLatitude(AppApplication.mockGPS.mLatitude);
location.setLongitude(AppApplication.mockGPS.mLongitude);
// public void setAddress(String var1) {
try {
RposedHelpers.callMethod(obj, "setAddress", AppApplication.mockGPS.address);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
return RposedHelpers.callMethod(originListener, method.getName(), args);
......
......@@ -7,9 +7,9 @@ import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
......@@ -46,7 +46,6 @@ import top.littlerich.virtuallocation.listener.GeoCoderListener;
import top.littlerich.virtuallocation.listener.MapClickListener;
import top.littlerich.virtuallocation.listener.MarkerDragListener;
import top.littlerich.virtuallocation.model.Gps;
import top.littlerich.virtuallocation.util.MapDistanceUtil;
import top.littlerich.virtuallocation.util.PermissionUtil;
import top.littlerich.virtuallocation.view.TopBanner;
......@@ -66,7 +65,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
private TextView tv_location;
boolean isFirstLoc = true;// 是否首次定位
// 百度定位相关
private LocationClient mLocClient;
private static LocationClient mLocClient;
private MyLocationConfiguration.LocationMode mCurrentMode;// 定位模式
private BitmapDescriptor mCurrentMarker;// 定位图标
private MapView mMapView;
......@@ -76,7 +75,6 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
private static Marker mMarker;
private static LatLng curLatlng;
private static GeoCoder mSearch;
public static double myGpslatitude, myGpslongitude;
DrawerLayout mDrawerLayout;
TopBanner mTopbanner;
private TextView mAboutAuthor;
......@@ -179,8 +177,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mCurrentLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LatLng ll = new LatLng(myGpslatitude, myGpslongitude);
setCurrentMapLatLng(ll);
mLocClient.start();
}
});
mBaiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {
......@@ -210,7 +207,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mStopMock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "虚拟定位已暂停!", Toast.LENGTH_SHORT).show();
mLocClient.stop();
bt_Ok.setText("立即穿越");
}
});
......@@ -224,6 +221,7 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mCurrentLocation.startAnimation(mOperatingAnim);
}
}
......@@ -243,7 +241,6 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker));
mLocClient.setLocOption(option);
mLocClient.start();
initOverlay();
}
......@@ -253,34 +250,44 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
*/
private void initOverlay() {
Gps configGPS = AppApplication.getConfigGPS();
LatLng ll = new LatLng(configGPS.mLatitude, configGPS.mLongitude);
final LatLng ll = new LatLng(configGPS.mLatitude, configGPS.mLongitude);
OverlayOptions oo = new MarkerOptions().position(ll).icon(bd).zIndex(9)
.draggable(true);
mMarker = (Marker) (mBaiduMap.addOverlay(oo));
new Handler(Looper.getMainLooper())
.postDelayed(new Runnable() {
@Override
public void run() {
// search初始化应该是异步的,刚刚启动就调用POI的话,会搜索失败
setCurrentMapLatLng(ll);
}
}, 1500);
}
/**
* setCurrentMapLatLng 设置当前坐标
*/
public static void setCurrentMapLatLng(LatLng arg0) {
// Debug.waitForDebugger();
curLatlng = arg0;
mMarker.setPosition(arg0);
if (mLocClient.isStarted()) {
mLocClient.stop();
}
// 设置地图中心点为这是位置
LatLng ll = new LatLng(arg0.latitude, arg0.longitude);
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
mBaiduMap.animateMapStatus(u);
Log.i("virjar", "移动坐标: " + ll + " " + ll.longitude + "," + ll.latitude);
MapDistanceUtil.GeoPoint geoPoint = MapDistanceUtil.gcj02ToGps84(arg0.latitude, arg0.longitude);
Log.i("virjar", "bd09:" + geoPoint.getLon() + "," + geoPoint.getLat());
LatLng reverseGeoRequestLatLng = new LatLng(geoPoint.getLat(), geoPoint.getLon());
// 根据经纬度坐标 找到实地信息,会在接口onGetReverseGeoCodeResult中呈现结果
mSearch.reverseGeoCode(
new ReverseGeoCodeOption()
.newVersion(0)
.pageNum(0)
.location(reverseGeoRequestLatLng)
.location(arg0)
.radius(150)
);
}
......
......@@ -89,7 +89,7 @@ public class AppApplication extends Application {
JSONObject jsonObject = new JSONObject(config);
double longitude = jsonObject.optDouble("longitude");
double latitude = jsonObject.optDouble("latitude");
return new Gps(latitude, longitude);
return new Gps(latitude, longitude, getAddress());
} catch (Exception e) {
e.printStackTrace();
return Config.COMPANY;
......@@ -108,6 +108,28 @@ public class AppApplication extends Application {
}
}
public static void storeAddress(String address) {
File configFile = new File(appApplication.getFilesDir(), "mockAddress.txt");
try {
FileUtils.writeLine(configFile, address);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getAddress() {
File configFile = new File(appApplication.getFilesDir(), "mockAddress.txt");
if (!configFile.exists()) {
return "";
}
try {
return FileUtils.readLine(configFile);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static void queryMockGPS(Context context) {
try {
Bundle bundle = context.getContentResolver()
......@@ -118,11 +140,12 @@ public class AppApplication extends Application {
}
double lat = bundle.getDouble("lat", -1);
double lng = bundle.getDouble("lng", -1);
Log.i(AppApplication.tag, "queryMockGPS: " + lng + "," + lat);
String address = bundle.getString("address");
Log.i(AppApplication.tag, "queryMockGPS: " + lng + "," + lat + " " + address);
if (lat == -1 && lng == -1) {
return;
}
mockGPS = new Gps(lat, lng);
mockGPS = new Gps(lat, lng, address);
} catch (Exception e) {
Log.e(AppApplication.tag, "error for queryMockGPS", e);
}
......
......@@ -5,10 +5,6 @@ import com.baidu.location.BDLocationListener;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import top.littlerich.virtuallocation.activity.MainActivity;
import static top.littlerich.virtuallocation.activity.MainActivity.myGpslatitude;
import static top.littlerich.virtuallocation.activity.MainActivity.myGpslongitude;
import static top.littlerich.virtuallocation.activity.MainActivity.setCurrentMapLatLng;
/**
......@@ -20,7 +16,7 @@ import static top.littlerich.virtuallocation.activity.MainActivity.setCurrentMap
public class AsyncLocationResultListener implements BDLocationListener {
private MapView mMapView;
boolean isFirstLoc = true;// 是否首次定位
boolean isFirstLoc;// 是否首次定位
//private double myGpslatitude, myGpslongitude;
public AsyncLocationResultListener(MapView mapView, boolean isFirstLoc) {
......@@ -37,12 +33,7 @@ public class AsyncLocationResultListener implements BDLocationListener {
return;
}
if (isFirstLoc) {
isFirstLoc = false;
MainActivity.myGpslatitude = location.getLatitude();
MainActivity.myGpslongitude = location.getLongitude();
LatLng ll = new LatLng(myGpslatitude, myGpslongitude);
setCurrentMapLatLng(ll);
}
LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
setCurrentMapLatLng(ll);
}
}
......@@ -10,6 +10,8 @@ import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import top.littlerich.virtuallocation.common.AppApplication;
/**
* 地理编码:1、正向地图编码 2、反向地图编码
* Created by xuqingfu on 2017/5/4.
......@@ -43,10 +45,14 @@ public class GeoCoderListener implements OnGetGeoCoderResultListener {
@Override
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
Log.w(AppApplication.tag, "error:" + result);
Toast.makeText(mContext, "抱歉,未能找到结果", Toast.LENGTH_LONG).show();
return;
}
Log.i("virjar", "逆地理:" + result);
mLocationTip.setText(String.format("伪造位置:%s", result.getAddress()));
String address = String.format("%s %s", result.getAddress(), result.getSematicDescription());
AppApplication.storeAddress(address);
Log.i(AppApplication.tag, "逆地理:" + result);
mLocationTip.setText(String.format("伪造位置:%s", address));
}
}
package top.littlerich.virtuallocation.listener;
import android.util.Log;
import android.widget.Button;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.model.LatLng;
import top.littlerich.virtuallocation.common.AppApplication;
import static top.littlerich.virtuallocation.activity.MainActivity.setCurrentMapLatLng;
/**
......@@ -42,7 +45,10 @@ public class MapClickListener implements BaiduMap.OnMapClickListener {
*/
@Override
public void onMapPoiClick(MapPoi mapPoi) {
// return false;
Log.i(AppApplication.tag, "clickPOI: " + mapPoi.getPosition()
+ " name:" + mapPoi.getName() +
" uid:" + mapPoi.getUid()
);
LatLng position = mapPoi.getPosition();
this.onMapClick(position);
}
......
......@@ -7,9 +7,17 @@ package top.littlerich.virtuallocation.model;
public class Gps {
public double mLatitude;
public double mLongitude;
public String address;
public Gps(double latitude, double longitude) {
mLatitude = latitude;
mLongitude = longitude;
}
public Gps(double latitude, double longitude, String address) {
this(latitude, longitude);
this.address = address;
}
}
......@@ -57,6 +57,7 @@ public class GPSContentProvider extends ContentProvider {
Gps configGPS = AppApplication.getConfigGPS();
bundle.putDouble("lat", configGPS.mLatitude);
bundle.putDouble("lng", configGPS.mLongitude);
bundle.putString("address", configGPS.address);
return bundle;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment