user187809
user187809

Reputation: 776

How to add markers to map box map?

I took the map box store locator example (https://docs.mapbox.com/help/tutorials/building-a-store-locator/) and am customizing it. The only thing I changed so far, are the lat-long of a couple of the items in the locations variable in the example. The ones that I changed don't show up in the map anymore, but the others do. The same lat-long combination works correctly if it is inside map box (on the map box website I mean). How do I make it work?

{
            "type": "Feature",
            "geometry": {
              "type": "Point",
              "coordinates": [
                -40.729423,
                73.981437
              ]
            },
            "properties": {
              "phoneFormatted": "(202) 234-7336",
              "phone": "2022347336",
              "address": "199 Ave A",
              "city": "New York",
              "country": "United States",
              "crossStreet": "at 15th St NW",
              "state": "D.C."
            }
          }

Upvotes: 0

Views: 231

Answers (1)

tmcw
tmcw

Reputation: 11882

Two problems: coordinate order and north/south east/west

This coordinate:

          "coordinates": [
            -40.729423,
            73.981437
          ]

Is in latitude, longitude order. Mapbox, and the GeoJSON standard format that this data is in, specifies a longitude, latitude order (similarly, KML, Shapefiles, and most other geospatial data formats specify longitude, latitude rather than the reverse).

Flip the coordinates:

          "coordinates": [
            73.981437,
            -40.729423
          ]

The other problem is that the coordinates are incorrect: New York is in the Western hemisphere, and longitude values are measured with a 0° prime meridian, with negative on the left and positive on the right (same as with math). Latitude is measured relative to the equator, with positive going up and negative down. Therefore, New York, which is in the northern hemisphere and western hemisphere, should have a negative longitude and positive latitude.

          "coordinates": [
            -73.981437,
            40.729423
          ]

Upvotes: 2

Related Questions