This is the 13th day of my participation in the August More Text Challenge. For more details, see “juejin.cn/post/698796…

preface

Modification mode:

1. Modify the latitude and longitude information through the GPX file

2, hook CLLocation to modify location (iOS reverse)

Application scenario 1:

When developing tests, try to simulate the location information of real users. For testing purposes, use the code to change the latitude and longitude without actually going to the corresponding location.

Application scenario 2: Punching in

I. Modify the latitude and longitude information in the GPX file

Example: Modify latitude and longitude, reverse geocoding to get location information

Then the system API is used to obtain the latitude and longitude, and then the system API is used to reverse geocoding to obtain the detailed location information.

For example, I want to simulate the location of -122.030237, 37.331705, and then get the detailed location of: United States CA Cupertino.

Steps:

  1. Simulate the location of an iOS device using Xcode:Use the GPX file to modify the location
  2. Map Change Service
  3. Location information is obtained by inverse geocoding.

1.1 Preparing the GPX File (” GPX File “under” iOS “Options”)

Before obtaining the virtual coordinates, first understand the coordinate system, so that the transformation

  1. For iOS, the native coordinate system is WGS-84

  2. Autonavi and domestic coordinate system: GCS-02

Lbs.amap.com/console/sho… 3. Baidu’s offset coordinate system: BD-09

  • example
<gpx version="1.1"

    creator="GMapToGPX 6.4 j - http://www.elsewhere.org/GMapToGPX/"

    xmlns="http://www.topografix.com/GPX/1/1"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">

    <wpt lat="31.255713422688655" lon="121.51010557702513">


        <cmt>North bund</cmt>


</gpx>




Copy the code

1.2 Use of GPX files

Once the debug App is running, check the location to simulate

  • The effect

1.3 Map Change Service [Optional]

Since Apple uses Autonavi’s map service in China, we can’t get the location information when we use the system API to reverse geocode the longitude and latitude of foreign countries, so we need to change the map service to Apple’s map service in foreign countries.

  • Operation steps:

Turn off cellular mobile data; Turn on wireless LAN and connect to a WiFi; Turn on flight mode; Open (v_p _n) app; Kill Apple’s maps app;

Re-open the “Maps” app of Apple, you can see that the “Amap” logo in the map application interface is missing

1.4 Obtain location information through inverse geocoding;

  • Development of Autonavi SDK for iOS platform: Locating apServices and Web services API: use of geocodes/inverse geocoding

IOS location, use of geocodes/inverse geocodes, and determine whether the longitude and latitude of the target is in the mainland

// Reverse geocoding
@interface AMapReGeocode : AMapSearchObject

Copy the code

Hook CLLocation to modify location (iOS reverse)

Modify the _ bit; Hook native API, directly replace your own


#import <CaptainHook/CaptainHook.h>
#import "WechatPodForm.h"
#import <UIKit/UIKit.h>

CHDeclareClass(CLLocation);

CHOptimizedMethod0(self.CLLocationCoordinate2D.CLLocation, coordinate){
    CLLocationCoordinate2D coordinate = CHSuper(0.CLLocation, coordinate);
    if(pluginConfig.location.longitude || pluginConfig.location.latitude ){
        coordinate = pluginConfig.location;
    }
    return coordinate;
}

CHConstructor{
    CHLoadLateClass(CLLocation);
    CHClassHook(0.CLLocation, coordinate);
}


Copy the code

III. HTML5 geolocation

Please see the original: kunnan.blog.csdn.net/article/det…

see also

For more content, please pay attention to the official account: iOS Reverse

IOS electronic signature Part 1 [Core principle: Rotate a specific screen] Application scenarios: Collect electronic signatures. The signature interface can be landscape screen and the rest of the pages can be portrait screen, clear and rewrite, flexibly control the prompt information, and view the merchant agreement

Kunnan.blog.csdn.net/article/det…