0

I am struggling to parse a geojson string returned from mapbox to get latitude and longitude co-ordinates, but struggling to get the data needed.

My current code is:

$json = file_get_contents($url);
$myPostcodeLat = $json->features[0]->center[0];
$myPostcodeLong = $json->features[0]->center[1];

enter image description here

I know the url is correct and is returning the data correctly, it is just the parsing of the data that is returned that isnt working for me.

I have tried a few of the other SO responses to parsing JSON data, but with no luck so far in getting the two required fields.

R2D2
  • 2,620
  • 4
  • 24
  • 46
  • 2
    `centre` vs `center`. Enable error_reporting, if you haven't already. – mario Feb 03 '15 at 20:21
  • Oops, thats an error in my post. Edited now! – R2D2 Feb 03 '15 at 20:28
  • 2
    Use `var_dump`, or paste your JSON into http://array.include-once.org/ to get a PHP-style representation. – mario Feb 03 '15 at 20:30
  • That's a really useful site, and has helped me track down the error. If you make this comment into an answer, I'll accept it. Thank you. – R2D2 Feb 03 '15 at 20:37
  • Great link @mario!!! That site is a lifesaver. Take the good man's advice and make your comment into an answer! – mikey_w Jul 02 '15 at 20:11
  • @mikey_w Thanks. This happens to be a project of mine, and specifically made for Stackoverflow questions no less. However I only rarely post it as comment even, because it otherwise looks too much like attention-addiction IMO. (However I'll go find a duplicate to cross-hyperlink a nice reference..) – mario Jul 02 '15 at 20:21

0 Answers0