Esri / arcgis-runtime-samples-android

ArcGIS Runtime SDK for Android Samples
https://developers.arcgis.com/android/
Apache License 2.0
666 stars 1.19k forks source link

ArcGIS so hard #527

Closed SenalChen closed 6 years ago

SenalChen commented 6 years ago

ArcGIS Android Issue Template

GitHub is ONLY used for issues pertaining to ArcGIS Runtime SDK Samples. Use GeoNet for any general ArcGIS Runtime Android SDK questions.

Is this something you can contribute? Send a pull request! New Samples, bug fixes and documentation fixes are welcome.

Neither of the above? Submit an issue:

Feature or Bug?

Behavior

Steps to Reproduce

1.Hi,I am a new man for the Arcgis and I don't how to calculate the longitude,latitude to the "x","y".Could you tell me how to get the formula equation please?Thank you very much. 2. 3. 4.

mbcoder commented 6 years ago

Can you give us some more details on exactly what you are trying to do so we can help with a good answer.

Answering your question directly, there are methods on a class called GeometryEngine which allow you to convert coordinates between spatial references. https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/geometry/GeometryEngine.html The Project method may be what you want.

If however the words "spatial reference" are drawing a blank then don't worry; just tell us what you want to do and we can point you are some code to make it nice and easy.

SenalChen commented 6 years ago

Hi,Thank you for your reply.Some question like that: Vector2D mercator = new Vector2D(); double x = lonLat.X 20037508.34 / 180; double y = Math.Log(Math.Tan((90 + lonLat.Y) Math.PI / 360)) / (Math.PI / 180); y = y * 20037508.34 / 180; mercator.X = x; mercator.Y = y; return mercator;

I don't know what is the formula for arcgis.Can you tell me what is the formula to get "x" and "y" ,is it different form google maps?

mbcoder commented 6 years ago

Geodesy is a complex subject which isn't necessarily something you need to be diving into. The ArcGIS Runtime SDK is designed to make life easy.

How about we step back from formulas and just look at what are you trying to do?

Maybe you are taking a coordinate from Google maps and are trying to show the same location in an app you are writing for Android? Maybe give me the numbers you are working with and I can show you how easy it is without having to use any formulas.

So you clearly have a coordinate which represents a location at a known point. Tell me what is it and I can probably guess the coordinate system and show you how to project it.

Trust me you'll be impressed how little code you need to write and how little you need to know about the maths of showing where things are on the surface of our planet - just tell me what you are trying to do.

SenalChen commented 6 years ago

Thanks a lot for answer me immediately.I just want to get tiles from ArcGIS.I just know the url and I can't transform deg to coordinate.If I know coordinate and zoom then I can get the tiles which I need.I don't have the code because I don't know how to write the formulas and what the formulas is .Thank you for help anyway.

mbcoder commented 6 years ago

Okay it sounds like you have a latitude and longitude coordinate and you want to centre the map at this point. This type of location is known as a WGS84 location. So all you need to do is the following:

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

        // create a map showing the streets basemap
        ArcGISMap mMap = new ArcGISMap(Basemap.createStreets());

        // set the map to be displayed in this view
        mMapView.setMap(mMap);

        // create a point from the lat / lon
        Point latLon = new Point(-3.1948891, 55.9465742, SpatialReferences.getWgs84());

        // set the viewpoint on the map centred at that point.  The scale will be 1:10000
        mMapView.setViewpointCenterAsync(latLon,10000);

The last 2 lines of code are the bit you need to add to an existing application.

Hopefully you can see that you really don't need to worry about formulas for converting between coordinate systems; it all happens in the background.

Does this answer your question?

mbcoder commented 6 years ago

If you do really want to convert your point between WGS84 and another spatial reference like WebMercator (commonly used in ESRI and Google basemaps for example), then you can convert like this:

        // create a point from the lat / lon
        Point latLon = new Point(-3.1948891, 55.9465742, SpatialReferences.getWgs84());

        // create a new point in the Web Mercator projection from the WGS84 point.
        Point mercatorPoint = (Point) GeometryEngine.project(latLon,SpatialReferences.getWebMercator());

Again the API does all the work for you, you don't need to understand how to project from A to B.

SenalChen commented 6 years ago

OK.How can I get the API? The google coordinate is the same as ESRI's?

mbcoder commented 6 years ago

I assume you are writing Android applications.

Product information is here: https://developers.arcgis.com/android/latest/

Also read the readme on this repro: https://github.com/Esri/arcgis-runtime-samples-android/blob/master/README.md

SenalChen commented 6 years ago

ok,I will try it . Thank you very much and sorry for disturbing you.So kindly you are,thanks.