将纬度和经度转换为 esri arcGIS MapPoint

发布于 2024-12-26 02:43:26 字数 654 浏览 3 评论 0原文

我在将纬度和经度值转换为 android esri arcGIS 地图点时遇到问题。这是我从 GPS 坐标获取纬度和经度值的代码:

LocationManager lm;
String towers;
double lat;
double longi;
TextView txt;

            lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Criteria crit = new Criteria();
            towers = lm.getBestProvider(crit, false);
            Location location = lm.getLastKnownLocation(towers);

            if(location != null)
            {
                lat = location.getLatitude();
                longi = location.getLongitude();
            }

现在我有了纬度和经度值。现在我需要的是将这些值转换为有效的 esri arcGIS MapPoint。谁能帮助我吗?

提前致谢。

I am having trouble in converting the latitude and longitude values into android esri arcGIS map Point. Here's my code to get latitude and longitude values from GPS coordinates:

LocationManager lm;
String towers;
double lat;
double longi;
TextView txt;

            lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Criteria crit = new Criteria();
            towers = lm.getBestProvider(crit, false);
            Location location = lm.getLastKnownLocation(towers);

            if(location != null)
            {
                lat = location.getLatitude();
                longi = location.getLongitude();
            }

now I have the latitude and longitude values. Now all I need is to convert these values into valid esri arcGIS MapPoint. Can anyone help me?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

栩栩如生 2025-01-02 02:43:26

假设您使用的是 ESRI Android API?如果是这样,请在地图上创建一个图形图层。然后创建一个点对象

com.esri.core.geometry.Point
Point myPoint = new Point();

,然后设置 x/y 值:

myPoint.setX(longi);
myPoint.setY(lat);

然后将 myPoint 添加到图形对象。

http://help.arcgis.com/en/arcgismobile/10.0/apis/ android/api/index.html

Assuming you're using the ESRI Android API? If so, create a graphics layer on your map. Then create a point object

com.esri.core.geometry.Point
Point myPoint = new Point();

then set the x/y values:

myPoint.setX(longi);
myPoint.setY(lat);

then add myPoint to the graphics object.

http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/index.html

谎言月老 2025-01-02 02:43:26

是的,这是可能的。但您不使用 ArcGis 中的位置管理器。

ArcGIS 有像 LocationListener 这样的预定义方法,即:OnStatusChangedListener

请参阅以下代码,将位置纬度和经度转换为 esri arcGIS MapPoint。

     mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

            /**
             * 
             */
      private static final long serialVersionUID = 1L;

      public void onStatusChanged(Object source, STATUS status) {
      if (source == mMapView && status == STATUS.INITIALIZED) {
      LocationService ls = mMapView.getLocationService();
      ls.setAutoPan(false);
      ls.setLocationListener(new LocationListener() {

      boolean locationChanged = false;

      // Zooms to the current location when first GPS fix
      // arrives.
      public void onLocationChanged(Location loc) {
      if (!locationChanged) {
      locationChanged = true;
      double locy = loc.getLatitude();
      double locx = loc.getLongitude();
      Point wgspoint = new Point(locx, locy);
      Point mapPoint = (Point) GeometryEngine.project(wgspoint,  

      SpatialReference.create(4326),

      mMapView.getSpatialReference());

      Unit mapUnit = mMapView.getSpatialReference().getUnit();
      double zoomWidth = Unit.convertUnits(

      SEARCH_RADIUS, Unit.create(LinearUnit.Code.MILE_US), mapUnit);
      Envelope zoomExtent = new Envelope(mapPoint, zoomWidth, zoomWidth);

      mMapView.setExtent(zoomExtent);

      GraphicsLayer gLayer = new GraphicsLayer();
      PictureMarkerSymbol symbol = new     
      PictureMarkerSymbol(getResources().getDrawable(R.drawable.twiz_car_red));
      Graphic graphic = new Graphic(mapPoint, symbol);
      //Graphic point=new Graphic(new Point(x, y),new    
      SimpleMarkerSymbol(Color.CYAN,20,STYLE.CIRCLE));   
      gLayer.addGraphic(graphic);
      mMapView .addLayer(gLayer);

         }
      }

      public void onProviderDisabled(String arg0) {

            }
      public void onProviderEnabled(String arg0) {
            }

      public void onStatusChanged(String arg0, int arg1,
      Bundle arg2) {

         }
        });
      ls.start();

     }
   }
});

Yes, it is possible. But you don't use the locationmanager in ArcGis.

ArcGIS has the predefined method like LocationListener, that is: OnStatusChangedListener.

See the below code for converting location latitude and longitude into esri arcGIS MapPoint.

     mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

            /**
             * 
             */
      private static final long serialVersionUID = 1L;

      public void onStatusChanged(Object source, STATUS status) {
      if (source == mMapView && status == STATUS.INITIALIZED) {
      LocationService ls = mMapView.getLocationService();
      ls.setAutoPan(false);
      ls.setLocationListener(new LocationListener() {

      boolean locationChanged = false;

      // Zooms to the current location when first GPS fix
      // arrives.
      public void onLocationChanged(Location loc) {
      if (!locationChanged) {
      locationChanged = true;
      double locy = loc.getLatitude();
      double locx = loc.getLongitude();
      Point wgspoint = new Point(locx, locy);
      Point mapPoint = (Point) GeometryEngine.project(wgspoint,  

      SpatialReference.create(4326),

      mMapView.getSpatialReference());

      Unit mapUnit = mMapView.getSpatialReference().getUnit();
      double zoomWidth = Unit.convertUnits(

      SEARCH_RADIUS, Unit.create(LinearUnit.Code.MILE_US), mapUnit);
      Envelope zoomExtent = new Envelope(mapPoint, zoomWidth, zoomWidth);

      mMapView.setExtent(zoomExtent);

      GraphicsLayer gLayer = new GraphicsLayer();
      PictureMarkerSymbol symbol = new     
      PictureMarkerSymbol(getResources().getDrawable(R.drawable.twiz_car_red));
      Graphic graphic = new Graphic(mapPoint, symbol);
      //Graphic point=new Graphic(new Point(x, y),new    
      SimpleMarkerSymbol(Color.CYAN,20,STYLE.CIRCLE));   
      gLayer.addGraphic(graphic);
      mMapView .addLayer(gLayer);

         }
      }

      public void onProviderDisabled(String arg0) {

            }
      public void onProviderEnabled(String arg0) {
            }

      public void onStatusChanged(String arg0, int arg1,
      Bundle arg2) {

         }
        });
      ls.start();

     }
   }
});
我的黑色迷你裙 2025-01-02 02:43:26

我从此处借用了一些

private Point ToGeographic(Point pnt)
{
    double mercatorX_lon = pnt.getX();
    double mercatorY_lat = pnt.getY();
    if (Math.abs(mercatorX_lon) < 180 && Math.abs(mercatorY_lat) < 90)
        return pnt;

    if ((Math.abs(mercatorX_lon) > 20037508.3427892) || (Math.abs(mercatorY_lat) > 20037508.3427892))
        return pnt;

    double x = mercatorX_lon;
    double y = mercatorY_lat;
    double num3 = x / 6378137.0;
    double num4 = num3 * 57.295779513082323;
    double num5 = Math.floor((double)((num4 + 180.0) / 360.0));
    double num6 = num4 - (num5 * 360.0);
    double num7 = 1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * y) / 6378137.0)));
    mercatorX_lon = num6;
    mercatorY_lat = num7 * 57.295779513082323;
    return new Point(mercatorX_lon, mercatorY_lat);
}

private Point ToWebMercator(Point pnt)
{
    double mercatorX_lon = pnt.getX();
    double mercatorY_lat = pnt.getY();
    if ((Math.abs(mercatorX_lon) > 180 || Math.abs(mercatorY_lat) > 90))
        return pnt;

    double num = mercatorX_lon * 0.017453292519943295;
    double x = 6378137.0 * num;
    double a = mercatorY_lat * 0.017453292519943295;

    mercatorX_lon = x;
    mercatorY_lat = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
    return new Point(mercatorX_lon, mercatorY_lat);
}

代码没有声称效率,但这至少是一个起点。

I've borrowed some code from here

private Point ToGeographic(Point pnt)
{
    double mercatorX_lon = pnt.getX();
    double mercatorY_lat = pnt.getY();
    if (Math.abs(mercatorX_lon) < 180 && Math.abs(mercatorY_lat) < 90)
        return pnt;

    if ((Math.abs(mercatorX_lon) > 20037508.3427892) || (Math.abs(mercatorY_lat) > 20037508.3427892))
        return pnt;

    double x = mercatorX_lon;
    double y = mercatorY_lat;
    double num3 = x / 6378137.0;
    double num4 = num3 * 57.295779513082323;
    double num5 = Math.floor((double)((num4 + 180.0) / 360.0));
    double num6 = num4 - (num5 * 360.0);
    double num7 = 1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * y) / 6378137.0)));
    mercatorX_lon = num6;
    mercatorY_lat = num7 * 57.295779513082323;
    return new Point(mercatorX_lon, mercatorY_lat);
}

private Point ToWebMercator(Point pnt)
{
    double mercatorX_lon = pnt.getX();
    double mercatorY_lat = pnt.getY();
    if ((Math.abs(mercatorX_lon) > 180 || Math.abs(mercatorY_lat) > 90))
        return pnt;

    double num = mercatorX_lon * 0.017453292519943295;
    double x = 6378137.0 * num;
    double a = mercatorY_lat * 0.017453292519943295;

    mercatorX_lon = x;
    mercatorY_lat = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
    return new Point(mercatorX_lon, mercatorY_lat);
}

I make no claims of efficiency, but it's a starting point at least.

一抹淡然 2025-01-02 02:43:26

免责声明:我不是这方面的专家,但想尽力提供帮助。 :)

现在有一个 ArcGIS Stack Exchange 站点。一直在添加更多信息,与互联网上发布的信息相比,这是一个很好的综合资源。

对于框架,我推荐 Android 版 GeoTools

顺便说一句,QGIS for Android 是 Marco Bernasocchi 的一个有趣项目,您可能会发现有帮助作为参考。

希望您能找到您要找的东西!

Disclaimer: I'm not an expert in this, but want to try to help. :)

There is now an ArcGIS Stack Exchange site. There's more information being added all the time and is a nice consolidated resource compared to what is out there disbursed on the interwebs.

For frameworks, I recommend GeoTools for Android.

As an aside, QGIS for Android is an interesting project from Marco Bernasocchi which you may find helpful as a reference.

Hope you can find what you're looking for!

小鸟爱天空丶 2025-01-02 02:43:26

我制作了一个函数,将位置点的两个参数转换为 arcgis 点:

private Point ConvertMyLocationPoint(final double x, final double y) {
        Point wgspoint = new Point(x, y);
        Point mapPoint = (Point) GeometryEngine.project(wgspoint, SpatialReference.create(4326),
                mMapView.getSpatialReference());

        return mapPoint;    
    }

i made a function that converts the two parameters of a location point to arcgis point :

private Point ConvertMyLocationPoint(final double x, final double y) {
        Point wgspoint = new Point(x, y);
        Point mapPoint = (Point) GeometryEngine.project(wgspoint, SpatialReference.create(4326),
                mMapView.getSpatialReference());

        return mapPoint;    
    }
樱花落人离去 2025-01-02 02:43:26

//将经纬度转换为地图点XY

- (AGSPoint *)agsPointFromLatitude:(double)latitude longitude:(double)longitude
  {
      double mercatorX = longitude * 0.017453292519943295 * 6378137.0;
     double a = latitude * 0.017453292519943295;
      double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a)));
      AGSPoint *obj = [AGSPoint pointWithX:mercatorX y:mercatorY spatialReference:    [AGSSpatialReference   wgs84SpatialReference]];


          return obj;
  }

//convert longitude and latitude to map point X Y

- (AGSPoint *)agsPointFromLatitude:(double)latitude longitude:(double)longitude
  {
      double mercatorX = longitude * 0.017453292519943295 * 6378137.0;
     double a = latitude * 0.017453292519943295;
      double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a)));
      AGSPoint *obj = [AGSPoint pointWithX:mercatorX y:mercatorY spatialReference:    [AGSSpatialReference   wgs84SpatialReference]];


          return obj;
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文