Help Center/ Cloud Phone Host/ Best Practices/ Simulating a Cloud Phone Location
Updated on 2026-08-27 GMT+08:00

Simulating a Cloud Phone Location

Introduction

There are four methods of determining the location of a phone: GPS longitude and latitude, base station, Wi-Fi, and IP address. CPH can simulate GPS and Wi-Fi location data.

Method

Precision

Scenario

GPS

High

Apps that require continuous positioning, such as map and navigation apps

Wi-Fi

Medium

Auxiliary positioning for GPS and base stations

Prerequisites

You have purchased a cloud phone server and connected to a cloud phone using ADB. For details, see Buying a Cloud Phone Server.

GPS

  1. Obtain the GPS longitude and latitude.

    The GPS data simulation of CPH is based on the World Geodetic System 1984 (WGS84). If other geodetic systems such as GCJ02 and BD09 are used, deviations may occur during data injection.

    Example:

    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener);
    private final LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
    // location contains GPS data such as the longitude and latitude.
            }
    };
  2. Inject GPS data.
    • Inject the GPS data using a shell command.

      On the cloud phone, run adb shell "echo 'parameters' > /data/gps/fifo". Separate parameters with colons.

      Table 1 describes the parameters.

      Table 1 GPS data injection

      Parameter

      Description

      Mandatory

      Default Value

      Remarks

      latitude

      Latitude.

      The north latitude is a positive value and the south latitude is a negative value.

      Yes

      22.657501

      Value range: –90.000000 to 90.000000

      Unit: degree (°)

      longitude

      Longitude.

      The east longitude is a positive value and the west longitude is a negative value.

      Yes

      114.055939

      Value range: –180.000000 to 180.000000

      Unit: degree (°)

      altitude

      Altitude.

      No

      51.0

      Unit: meter

      speed

      Speed.

      No

      0.0

      Unit: meter

      bearing

      Azimuth.

      0° indicates the true north, 90° indicates the true east, 180° indicates the true south, and 270° indicates the true west.

      No

      30.0

      Value range: 0.0 to 360.0

      Unit: degree (°)

      accuracy

      Positioning accuracy.

      No

      90.0

      Unit: meter

      Example: Change the cloud phone location to 114.055939 degrees East longitude and 22.657501 degrees North latitude.

      adb -s 127.0.0.1:local-idle-port shell "echo 'longitude=114.055939:latitude=22.657501' > /data/gps/fifo"
    • Continuously inject GPS data (non-blocking injection recommended).

      Use self-developed or third-party SDK application code to continuously inject GPS data in O_NONBLOCK (non-blocking) mode.

      Example:

      #define GPSFifoName "/data/gps/fifo"
      if((fifo_fd = open(GPSFifoName, O_WRONLY | O_NONBLOCK)) < 0) {
      ALOGE("open fifo "%s" (write) fail, error = %s\n", GPSFifoName, strerror(errno));
      return;
      }
      // Use colons (:) to separate cmd parameters.
      char* cmd = "longitude=113.370592:latitude=23.123642";
      len = strlen(cmd);
      if(write(fifo_fd, cmd, len) != len) {
      ALOGE("%s: write "%s" to "%s" fail: %s", FUNCTION, cmd, GPSFifoName, strerror(errno));
      }

Wi-Fi

  1. Obtain Wi-Fi data.

    Example:

    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiConnection = wifiManager.getConnectionInfo();
    if (wifiConnection != null) {
        String bssid =  wifiConnection.getBSSID();
    }
  2. Inject the Wi-Fi data.

    Configure com.cph.wifi.bssid with the Wi-Fi BSSID to inject the Wi-Fi data.

    Example:

    setprop com.cph.wifi.bssid 02:00:00:00:00:00