2012-01-10 51 views
6

Tôi đang gặp khó khăn trong việc chuyển đổi các giá trị vĩ độ và kinh độ thành bản đồ esri arcGIS android. Đây là mã của tôi để nhận các giá trị vĩ độ và kinh độ từ tọa độ GPS:Chuyển đổi vĩ độ và kinh độ thành esri arcGIS MapPoint

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

bây giờ tôi có các giá trị vĩ độ và kinh độ. Bây giờ tất cả những gì tôi cần là chuyển đổi các giá trị này thành bản đồ esri arcGIS MapPoint hợp lệ. Ai giúp tôi với?

Xin cảm ơn trước.

Trả lời

4

Tuyên bố từ chối trách nhiệm: Tôi không phải là chuyên gia trong lĩnh vực này, nhưng tôi muốn cố gắng trợ giúp. :)

Hiện tại có trang web ArcGIS Stack Exchange. Có thêm thông tin được thêm vào tất cả các thời gian và là một nguồn tài nguyên hợp nhất tốt đẹp so với những gì được ra có giải ngân trên interwebs.

Đối với các khuôn khổ, tôi khuyên bạn nên GeoTools cho Android.

Là một sang một bên, QGIS for Android là một dự án thú vị từ Marco Bernasocchi mà bạn có thể thấy hữu ích như một tài liệu tham khảo.

Hy vọng bạn có thể tìm thấy những gì bạn đang tìm kiếm!

6

Giả sử bạn đang sử dụng API Android ESRI? Nếu vậy, hãy tạo một lớp đồ họa trên bản đồ của bạn. Sau đó tạo ra một đối tượng điểm

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

sau đó đặt x/y giá trị:

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

sau đó thêm myPoint cho đối tượng đồ họa.

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

6

Có, có thể. Nhưng bạn không sử dụng trình quản lý vị trí trong ArcGis.

ArcGIS có phương pháp được xác định trước như LocationListener, nghĩa là: OnStatusChangedListener.

Xem mã bên dưới để chuyển đổi vị trí vĩ độ và kinh độ thành 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(); 

    } 
    } 
}); 
5

Tôi đã mượn một số mã từ 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); 
} 

tôi làm cho không có tuyên bố có hiệu quả, nhưng đó là một điểm khởi đầu ít nhất.

+0

thực sự tuyệt vời sooooooooooooooooooooo – ROR

0

// chuyển đổi kinh độ và vĩ độ để lập bản đồ điểm 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; 
    } 
4

tôi đã thực hiện một chức năng có thể chuyển đổi hai thông số của một điểm vị trí để điểm 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;  
    } 
Các vấn đề liên quan