Sample code for positioning function of arcgis android

  • 2021-09-05 00:44:45
  • OfStack

Regarding the positioning function and development, Baidu's positioning function has been done long ago. At first, I had an idea to integrate Baidu's Loc V3.2 positioning SDK. But after all, it is an idea, but yesterday, I asked the technical group, and a friend in it talked about the implementation method of integrating Baidu's status SDK. Suddenly, I thought for a while, and then I was very excited to operate. According to one demo given by a friend. After doing it for two days, the function was finally realized. As for the beauty of the interface or the display of the style, this is lazy.

http://developer.baidu.com/map/sdk-android.htm

This is Baidu's SDK. Help documentation.

The first time to see the realization of this positioning, I feel that it can be realized according to the steps, and the parameters of this setting will be set. Actually, it does. It's simple!
First locate the current latitude and longitude, and then set the anchor point.


  private double lat=-1;// Latitude 
  private double lon=-1;// Longitude 
 public class MainActivity extends ActivityBas{
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
  ArcGISRuntime.setClientId("1eFHW78avlnRUPHm");// Cancel arcgis Default icon 
  dingweilocation() ; 
  mapView.centerAt(lat, lon, true);// Set the positioning center point 
  mapView.setScale(1105828.1803422251);// Set the display scale 
  }

private void dingweilocation() {
    // Positioning method 
  LocationDisplayManager locationDisplayManager = mapView.getLocationDisplayManager();
  locationDisplayManager.setLocationListener(new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
      
      String bdlat=location.getLatitude()+""; 
      String bdlon=location.getLongitude()+"";
      if (bdlat.indexOf("E")==-1|bdlon.indexOf("E")==-1){
      // The judgment here is because, maybe because gps Signal problem, the longitude and latitude located are abnormal. 
        Log.i(" Positioning ",lat+"?"+lon);
        lat = location.getLatitude();// Latitude 
        lon = location.getLongitude();// Longitude 
      }
    }

    @Override
    public void onStatusChanged(String s, int i, Bundle bundle) {
    }

    @Override
    public void onProviderEnabled(String s) {
    }

    @Override
    public void onProviderDisabled(String s) {
    }
  });
  locationDisplayManager.start();
}
 }

Related articles: