ArcGIS的:如何获得设备的位置 [英] Arcgis : how to get device location

查看:183
本文介绍了ArcGIS的:如何获得设备的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

枝我试图实现我的应用程序这个codeS,但它不工作,我不知道我在哪里出了错。

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

这是我看到的是地图中的唯一的事情。只是一个普通的缩小地图。

我会很感激,如果有人谁可以帮助我如何与所显示的地图上的蓝色圆点获取当前位置。

这是我的MainActivity.class

 公共类的HelloWorld扩展活动{
图形页面mMapView = NULL;
ArcGISTiledMapServiceLayer tileLayer;
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    //从XML布局中的地图和初始区
        mMapView =(图形页面)findViewById(R.id.map);         mMapView.addLayer(新ArcGISTiledMapServiceLayer(
             http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer));         mMapView.setOnStatusChangedListener(新OnStatusChangedListener(){           公共无效onStatusChanged(对象源,状态的状态){
             如果(来源== mMapView&放大器;&放大器;状态== STATUS.INITIALIZED){
               LocationService LS = mMapView.getLocationService();
               ls.setAutoPan(假);               ls.start();
             }           }         });    }
保护无效的onPause(){
    super.onPause();
    mMapView.pause();
   }@覆盖
保护无效onResume(){
    super.onResume();
    mMapView.unpause();
}}


解决方案

这是一个code,吸引了我的位置,通过供应商和GPS每隔1秒。
让我们首先声明变量:

 私人GraphicsLayer myGraphicalLayer;
图形页面mMapView;
    ArcGISLocalTiledLayer baseLayer;
私人的LocationManager mlocManager;
    私人LocationListener的mlocListener;

在功能的onCreate我们称之为LocationListener的:

  mlocManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocListener =新MyLocationListener();
        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,mlocListener);
        mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1000,0,mlocListener);
//加载地图
        mMapView =(图形页面)findViewById(R.id.localMap);
        baseLayer =新ArcGISLocalTiledLayer(basemapurl);
        mMapView.addLayer(baseLayer);
//定义我的立场层
        myGraphicalLayer =新GraphicsLayer();

那么功能吸引我的位置:

 私人无效SetMyLocationPoint(最终双X,最后双Y){
        的PictureMarkerSymbol myPin =新的PictureMarkerSymbol(getResources()。getDrawable(
                R.drawable.mylocation_icon));        点wgspoint =新的点(X,Y);
        点的MapPoint =(点)GeometryEngine.project(wgspoint,SpatialReference.create(4326)
                mMapView.getSpatialReference());        图文myPinGraphic =新的图形(MapPoint的,myPin);        尝试{
            myGraphicalLayer.removeAll();
        }赶上(例外五){
            e.printStackTrace();
        }        myGraphicalLayer.addGraphic(myPinGraphic);
        myGraphicalLayer.setVisible(真);
        mMapView.addLayer(myGraphicalLayer);    }

请实现MyLocationListener让你快速定位内部类,并让它调用函数命名SetMyLocationPoint这样的方式:

 公共类MyLocationListener实现LocationListener的{        @覆盖
        公共无效onLocationChanged(位置LOC){
            SetMyLocationPoint(loc.getLongitude(),loc.getLatitude());
        }        @覆盖
        公共无效onProviderDisabled(字符串提供商){
            Toast.makeText(getApplicationContext(),提供者启用,Toast.LENGTH_SHORT)
                    。显示();
        }        @覆盖
        公共无效onProviderEnabled(字符串提供商){
            Toast.makeText(getApplicationContext(),提供者禁用,Toast.LENGTH_SHORT)
                    。显示();
        }        @覆盖
        公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){
        }
    }

Hie i tried to implement this codes in my application but it doesnt work , i dont know where i went wrong.

basically, when i launch the sample of the device location. it doesnt show me where is my current location and i dont see any blue dots that resembles the current location i am at.

the only thing that i see is the map . just a plain zoom out map.

I would be really thankful if someone who could help me out on how to get the current location with the blue dots that is displayed on the map..

this is my 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();
}   

}

解决方案

this is a code that draws my location every 1 second via provider and GPS . let's first declare variables :

private GraphicsLayer myGraphicalLayer;
MapView mMapView;
    ArcGISLocalTiledLayer baseLayer;
private LocationManager mlocManager;
    private LocationListener mlocListener;

in onCreate function 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();

then a function to draw my location :

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);

    }

make internal class that implements MyLocationListener to get you instant location, and let it call the function named SetMyLocationPoint like this way :

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) {
        }
    }

这篇关于ArcGIS的:如何获得设备的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆