Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>char *buf = [routeGeom UTF8String]; int bestGuess = 1 &lt;&lt; (whatever); routePoints = malloc(sizeof(CLLocationCoordinate2D) * bestGuess); for (int i = 0; buf != NULL; buf = strchr(buf+1,'['), ++i) { if (i &gt;= bestGuess) { bestGuess &lt;&lt;= 1; routePoints = realloc(routePoints, sizeof(CLLocationCoordinate2D) * bestGuess); } sscanf(buf+1, "%f,%f,", &amp;(routePoints + i)-&gt;latitude, &amp;(routePoints + i)-&gt;longitude); } </code></pre> <p><br> Pick a good starting value for <code>(whatever)</code> so that 2<sup>whatever</sup> is representative of an average number of points in a route. If you can't, you could try guessing the number based on the length of the string. Otherwise, if you want to be exact, you could parse the string twice, first counting, then create <code>routePoints</code>, then parse the data, in which case you wouldn't need the realloc section.</p> <p><strong>Edit:</strong></p> <p>Another option. This assumes that CLLocationCoordinate2D is simply a struct of 2 floats, in the same order as the data in the string.</p> <pre><code>char *buf = [routeGeom UTF8String]; int bestGuess = 1 &lt;&lt; (whatever); float *tmpFloats = (float *)malloc(sizeof(float) * bestGuess); float *index = tmpFloats; for (int i = 0; buf != NULL; buf = strchr(buf+1,'['), ++i, index += 2) { if (i &gt;= bestGuess) { bestGuess &lt;&lt;= 1; tmpFloats = (float *)realloc(tmpFloats, sizeof(float) * bestGuess); } sscanf(buf+1, "%f,%f,", index, index + 1); } CLLocationCoordinate2D *routePoints = (CLLocationCoordinate2D *)tmpFloats; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload