Add point from location

3432
9
11-18-2014 03:18 PM
HaniDraidi
Occasional Contributor II

Hello all, I am new to ArcGIS-Android development environment.

I want to draw a point that shows my location, I used the following steps:

Defining a location variableز

2- Get the longitude and latitude from the location.

3- Creating a point from the longitude and latitude.

However, when I define the point that takes the longitude and latitude, I get an error (shown below in the screenshot). What might be the issue here?

Clip_839.jpg

Here is my code:

Location loc = null;

               

               

                double lon,lat;

                lon= loc.getLongitude();

                lat= loc.getLatitude();

                Point mlocation=new Point(lat,lon);

0 Kudos
9 Replies
MengyiGuo
Occasional Contributor

Try the following code to show the point.. also check what you imported.. the Point class should be com.esri.core.geometry.Point , and I think Android has a Point class as well.

// create a point marker symbol (red, size 10, of type circle)

SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.RED, 10, SimpleMarkerSymbol.STYLE.CIRCLE);  // create a point at x=-302557, y=7570663 (for a map using meters as units; this depends // on the spatial reference)

Point pointGeometry = new Point(-302557, 7570663);  // create a graphic with the geometry and marker symbol

Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);  // add the graphic to the graphics layer

graphicsLayer.addGraphic(pointGraphic);

HaniDraidi
Occasional Contributor II

Dear Mengyi,

I did exactly what you suggested (using this link) in a new project, but I get an error when creating the graphic point  using :

Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);

I get this error: "The constructor Graphic(Point, SimpleMarkerSymbol) is undefined"

And it asks me to change the type of point to geometry or remove the arguments!!

0 Kudos
MengyiGuo
Occasional Contributor
Graphic(Geometry geometry, Symbol symbol)

Instantiates a new Graphic object from the specified geometry and symbol.

The constructor should exist. May I confirm the SDK version you are working with?

0 Kudos
HaniDraidi
Occasional Contributor II

Android SDK Tools Rev. 23.0.5

Android SDK Platforms-Tools Rev 21

Android SDK Build-Tools Rev 20

Android 5.0 (API 21)

SDK Plaform Rev. 1

Android 4.4W (API 20)

SDK Plaform Rev. 1

Android 4.4.2 (API 17)

SDK Platform Rev. 3

Google APIs Rev. 3

Android Support Library Rev. 21.0.1

0 Kudos
MengyiGuo
Occasional Contributor

Did you installed the eclipse plugin for ArcGIS Runtime SDK for Android? What is the version for that one?

0 Kudos
HaniDraidi
Occasional Contributor II

Yes, plugin is installed; version 10.2.4.201410031154

Clip_840.jpg

0 Kudos
MengyiGuo
Occasional Contributor

Would you like to send your code to me? Maybe I can take a look at it.

mguo@esri.com

HaniDraidi
Occasional Contributor II

Dear Mengyi,

Thank you for your prompt contribution.

I solved the point rendering problem by using this:

// create a point marker symbol (red, size 10, of type circle)

                        SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.RED, 10, SimpleMarkerSymbol.STYLE.CIRCLE);

                        // create a point at x=-302557, y=7570663 (for a map using meters as units; this depends         // on the spatial reference)

                        Geometry pointGeometry = new com.esri.core.geometry.Point(-302557, 7570663);

                             

                        // create a graphic with the geometry and marker symbol

                        Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);

                        // add the graphic to the graphics layer

                        graphicsLayer.addGraphic(pointGraphic);

It seems that I should use Geometry pointGeometry = new com.esri.core.geometry.Point(-302557, 7570663);instead of Point pointGeometry = new Point(-302557, 7570663);

0 Kudos
MengyiGuo
Occasional Contributor

I see. However, com.esri.core.geometry.Point is the subclass of Geometry. So I think

Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);

should work for com.esri.core.geometry.Point

The reason why it gives the error maybe Point you are using is the Point class in Android rather than com.esri.core.geometry.Point. You can also try import com.esri.core.geometry and use Point directly.

Anyway, I'm glad your issue is solved:)

0 Kudos