arcgis android 定位,android – Arcgis:如何获取设备位置

我试图在我的应用程序中实现此代码,但它不起作用,我不知道我哪里出错了.

基本上,当我启动设备位置的样本时.它没有告诉我我当前的位置在哪里,我没有看到任何类似于我当前位置的蓝点.

我看到的唯一一件事是地图.只是一个简单的缩小地图.

如果有人可以帮我解决如何使用地图上显示的蓝点来获取当前位置,我将非常感激.

这是我的MainActivity.class

public class HelloWorld extends Activity {

MapView mMapView = null;

ArcGISTiledMapServiceLayer tileLayer;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

// Retrieve the map and initial extent from XML layout

mMapView = (MapView) findViewById(R.id.map);

mMapView.addLayer(new ArcGISTiledMapServiceLayer(

"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));

mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

public void onStatusChanged(Object source, STATUS status) {

if (source == mMapView && status == STATUS.INITIALIZED) {

LocationService ls = mMapView.getLocationService();

ls.setAutoPan(false);

ls.start();

}

}

});

}

protected void onPause() {

super.onPause();

mMapView.pause();

}

@Override

protected void onResume() {

super.onResume();

mMapView.unpause();

}

}

解决方法:

这是一个代码,每1秒通过提供商和GPS绘制我的位置.

让我们首先声明变量:

private GraphicsLayer myGraphicalLayer;

MapView mMapView;

ArcGISLocalTiledLayer baseLayer;

private LocationManager mlocManager;

private LocationListener mlocListener;

在onCreate函数WE CALL LocationListener:

mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

mlocListener = new MyLocationListener();

mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, mlocListener);

mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, mlocListener);

// loading the map

mMapView = (MapView) findViewById(R.id.localMap);

baseLayer = new ArcGISLocalTiledLayer(basemapurl);

mMapView.addLayer(baseLayer);

// defining my position layer

myGraphicalLayer = new GraphicsLayer();

然后绘制我的位置的函数:

private void SetMyLocationPoint(final double x, final double y) {

PictureMarkerSymbol myPin = new PictureMarkerSymbol(getResources().getDrawable(

R.drawable.mylocation_icon));

Point wgspoint = new Point(x, y);

Point mapPoint = (Point) GeometryEngine.project(wgspoint, SpatialReference.create(4326),

mMapView.getSpatialReference());

Graphic myPinGraphic = new Graphic(mapPoint, myPin);

try {

myGraphicalLayer.removeAll();

} catch (Exception e) {

e.printStackTrace();

}

myGraphicalLayer.addGraphic(myPinGraphic);

myGraphicalLayer.setVisible(true);

mMapView.addLayer(myGraphicalLayer);

}

使用实现MyLocationListener的内部类来获取即时位置,并让它像这样调用名为SetMyLocationPoint的函数:

public class MyLocationListener implements LocationListener {

@Override

public void onLocationChanged(Location loc) {

SetMyLocationPoint(loc.getLongitude(), loc.getLatitude());

}

@Override

public void onProviderDisabled(String provider) {

Toast.makeText(getApplicationContext(), "provider enabled", Toast.LENGTH_SHORT)

.show();

}

@Override

public void onProviderEnabled(String provider) {

Toast.makeText(getApplicationContext(), "provider disabled", Toast.LENGTH_SHORT)

.show();

}

@Override

public void onStatusChanged(String provider, int status, Bundle extras) {

}

}

标签:android,map,arcgis,esri

来源: https://codeday.me/bug/20190517/1120994.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值