0

hi i have a big problem i try 3 weaks to solve it but i didn't make anything i have or an errors or i don't take nothing from the results. i pas an array from query ST_AsGeoJSON from a php code in the javascript code. there are in the same file html this two codes i get the array from php to javascrypt with this line of code

var jsonAr= <?php echo json_encode($Arresu) ?>; 

if i print the jsonAr i receve with document.write(jsonAr); it is give me this format

{ "type":"LineString","coordinates":[[25.9980559326738,39.2420282528175],......,,[26.0486275566016,39.2291388086281]]},{"type":"LineString","coordinates":[[26.0486275566016,39.2291388086281],......[]]}

if i try to take the coordinates and pot it in an array i try this jsonAr.coordinates[0][0] but i did not take any result , i don't know how i take the coordinates

3
  • add console.log('jsonAr'); after the variable definition to see what JS has for that variable. This will help you diagnose your own problem more easily. Commented Nov 12, 2014 at 21:35
  • you need to parse that JSON string first. Use var jsonAr = JSON.parse(<?php echo json_encode($Arresu) ?>); Commented Nov 12, 2014 at 21:36
  • if i use JSON.parser is say me JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 647 of the JSON data Commented Nov 12, 2014 at 23:01

2 Answers 2

1

jsonAr.coordinates[0] will give you the first coordinate. jsonAr.coordinates[0][0] only gives you the first number of the first coordinate.

Sign up to request clarification or add additional context in comments.

1 Comment

I try it but the firefox console say jsonAr.coordinates is undefined
0

It looks like you want to assign two values to your variable

jsonAr = {...},{...}

Maby you want to try somethig like this:

jsonAr = [{...},{...}]
jsonAr[0].coordinates[0][0] //25.9980559326738

Or

jsonAr = [{...},{...}]
draw_function(jsonAr[0].coordinates[0][0],jsonAr[1].coordinates[0][0]) //25.9980559326738,26.0486275566016

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.