The SimpleMarker is not show up on the map

197
3
Jump to solution
10-21-2021 06:07 AM
BTDS_GISAdmin
New Contributor II

I tried to add the simple marker on the location with the latitude and longitude. However, the marker is not showing up on the map. The following is the code to display marker.

func addSimpleMarkerSymbol() {
    let symbol = AGSSimpleMarkerSymbol(style: .diamond, color: .red, size: 28)
    
    let point = AGSPoint(x: Double(self.longitude), y: Double(self.latitude), spatialReference: .wgs84())
    
    let graphic = AGSGraphic(geometry: point, symbol: symbol, attributes: nil)
    
    self.graphicsOverlay.graphics.add(graphic)
    
    self.graphicsOverlays.add(self.graphicsOverlay)

    
  }

 

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

A few things worth checking:

  • Are the coordinates in correct spatial reference? If they are in web mercator, you'll need to first project them into WGS 84, or pass in the Web Mercator sr when creating the point.
  • Are the order of longitude and latitude correct? A common mistake is that the x-y and lon-lat are mismatched. Say if you pass in a latitude that is not in the range of (-90°, 90°), then the point is invalid and won't show as a graphic
  • Are you adding the graphics overlays to the map view? It would be simpler to just add once
mapView.graphicsOverlays.add(graphicsOverlay)

and avoid adding the graphicsOverlay multiple times.

---

Making slight change to your code and it works for me.

let point = AGSPoint(x: -118.41612, y: 33.37432, spatialReference: .wgs84())
let symbol = AGSSimpleMarkerSymbol(style: .diamond, color: .red, size: 28)
let graphic = AGSGraphic(geometry: point, symbol: symbol)
self.graphicsOverlay.graphics.add(graphic)

// Only add once for each graphics overlay.
self.mapView.graphicsOverlays.add(self.graphicsOverlay)

Ting_0-1634831890938.png

View solution in original post

0 Kudos
3 Replies
RyanOlson1
Esri Contributor

Are you adding the graphics overlays to the mapview?

0 Kudos
BTDS_GISAdmin
New Contributor II

Ryan,

 

Yes, the self is a mapview.

So that the self.graphicsOverlays.add(self.graphicsOverlay)

it add the graphicsOverlay variable to the mapview graphicsOverlays

0 Kudos
Ting
by Esri Contributor
Esri Contributor

A few things worth checking:

  • Are the coordinates in correct spatial reference? If they are in web mercator, you'll need to first project them into WGS 84, or pass in the Web Mercator sr when creating the point.
  • Are the order of longitude and latitude correct? A common mistake is that the x-y and lon-lat are mismatched. Say if you pass in a latitude that is not in the range of (-90°, 90°), then the point is invalid and won't show as a graphic
  • Are you adding the graphics overlays to the map view? It would be simpler to just add once
mapView.graphicsOverlays.add(graphicsOverlay)

and avoid adding the graphicsOverlay multiple times.

---

Making slight change to your code and it works for me.

let point = AGSPoint(x: -118.41612, y: 33.37432, spatialReference: .wgs84())
let symbol = AGSSimpleMarkerSymbol(style: .diamond, color: .red, size: 28)
let graphic = AGSGraphic(geometry: point, symbol: symbol)
self.graphicsOverlay.graphics.add(graphic)

// Only add once for each graphics overlay.
self.mapView.graphicsOverlays.add(self.graphicsOverlay)

Ting_0-1634831890938.png

View solution in original post

0 Kudos