Example usage for org.json JSONArray getDouble

List of usage examples for org.json JSONArray getDouble

Introduction

In this page you can find the example usage for org.json JSONArray getDouble.

Prototype

public double getDouble(int index) throws JSONException 

Source Link

Document

Get the double value associated with an index.

Usage

From source file:eu.sathra.io.IO.java

private Object getValue(JSONArray array, Class<?> clazz) throws Exception {

    Object parsedArray = Array.newInstance(clazz, array.length());

    for (int c = 0; c < array.length(); ++c) {
        if ((clazz.equals(String.class) || clazz.isPrimitive()) && !clazz.equals(float.class)) {
            Array.set(parsedArray, c, array.get(c));
        } else if (clazz.equals(float.class)) {
            Array.set(parsedArray, c, (float) array.getDouble(c));
        } else if (clazz.isArray()) {
            // nested array
            Array.set(parsedArray, c, getValue(array.getJSONArray(c), float.class)); // TODO
        } else {/*from  w  w  w . java2  s. c  o  m*/
            Array.set(parsedArray, c, load(array.getJSONObject(c), clazz));
        }
    }

    return parsedArray;
}

From source file:com.suarez.cordova.mapsforge.MapsforgePlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("global-status".equals(action)) {
        this.status();
        callbackContext.success();//from w ww.  ja va  2s.  com
        return true;
    } else if (action.contains("native-")) {
        if ("native-set-center".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setCenter(args.getDouble(0), args.getDouble(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-zoom".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.show();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
            return true;
        } else if ("native-hide".equals(action)) {
            MapsforgeNative.INSTANCE.hide();
            return true;
        } else if ("native-marker".equals(action)) {
            try {
                Activity context = this.cordova.getActivity();

                int markerId = context.getResources().getIdentifier(args.getString(0), "drawable",
                        context.getPackageName());
                if (markerId == 0) {
                    Log.i(MapsforgePlugin.TAG, "Marker not found...using default marker: marker_green");
                    markerId = context.getResources().getIdentifier("marker_green", "drawable",
                            context.getPackageName());
                }

                int markerKey = MapsforgeNative.INSTANCE.addMarker(markerId, args.getDouble(1),
                        args.getDouble(2));
                callbackContext.success(markerKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-polyline".equals(action)) {

            try {
                JSONArray points = args.getJSONArray(2);

                if (points.length() % 2 != 0)
                    throw new JSONException("Invalid array of coordinates. Length should be multiple of 2");

                int polylineKey = MapsforgeNative.INSTANCE.addPolyline(args.getInt(0), args.getInt(1), points);

                callbackContext.success(polylineKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-delete-layer".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.deleteLayer(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-initialize".equals(action)) {

            try {

                MapsforgeNative.createInstance(this.cordova.getActivity(), args.getString(0), args.getInt(1),
                        args.getInt(2));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-max-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMaxZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-min-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMinZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-controls".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setBuiltInZoomControls(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-clickable".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setClickable(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-scale".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.showScaleBar(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy-cache".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.destroyCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            }

            return true;
        } else if ("native-map-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMapFilePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException iae) {
                callbackContext.error(iae.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-cache-name".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-theme-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setRenderThemePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-stop".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStop();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-start".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStart();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-online".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOnline(args.getString(0), args.getString(1), args.getString(2),
                        args.getString(3), args.getInt(4));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-offline".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOffline(args.getString(0), args.getString(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    } else if (action.contains("cache-")) {
        if ("cache-get-tile".equals(action)) {

            try {
                final long x = args.getLong(0);
                final long y = args.getLong(1);
                final byte z = Byte.parseByte(args.getString(2));
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {
                    public void run() {
                        try {
                            String path = MapsforgeCache.INSTANCE.getTilePath(x, y, z);
                            callbacks.success(path);
                        } catch (IOException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-initialize".equals(action)) {

            try {
                MapsforgeCache.createInstance(cordova.getActivity(), args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-map-path".equals(action)) {

            try {
                final String mapFile = args.getString(0);
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setMapFilePath(mapFile);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-age".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheAge(args.getLong(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-cleaning-trigger".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanCacheTrigger(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-enabled".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheEnabled(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-external".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setExternalCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-name".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-tile-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setTileSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-clean-destroy".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanOnDestroy(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-theme-path".equals(action)) {

            try {
                final CallbackContext callbacks = callbackContext;
                final String themePath = args.getString(0);

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setRenderTheme(themePath);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-screen-ratio".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setScreenRatio(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-overdraw".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setOverdrawFactor(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-destroy".equals(action)) {
            try {
                MapsforgeCache.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    }
    return false; // Returning false results in a "MethodNotFound" error.
}

From source file:com.yoncabt.ebr.util.ResultSetDeserializer.java

public List<Object[]> getData() {
    List<Object[]> ret = new ArrayList<>();
    JSONArray arr = jo.getJSONArray("values");
    for (int i = 0; i < arr.length(); i++) {
        List<Object> column = new ArrayList<>();
        JSONArray row = arr.getJSONArray(i);
        for (int j = 0; j < types.size(); j++) {
            if (row.isNull(j)) {
                column.add(null);//www . j  av a2 s . c  o m
            } else {
                switch (types.get(j)) {
                case DATE:
                    column.add(new Date(row.getLong(j)));
                    break;
                case STRING:
                    column.add(row.getString(j));
                    break;
                case INTEGER:
                    column.add(row.getInt(j));
                    break;
                case LONG:
                    column.add(row.getLong(j));
                    break;
                case DOUBLE:
                    column.add(row.getDouble(j));
                    break;
                default:
                    throw new AssertionError();
                }
            }
        }
        ret.add(column.toArray());
    }
    return ret;
}

From source file:com.graphhopper.http.NearestServletWithEleIT.java

@Test
public void testWithEleQuery() throws Exception {
    JSONObject json = nearestQuery("point=43.730864,7.420771&elevation=true");
    assertFalse(json.has("error"));
    JSONArray point = json.getJSONArray("coordinates");
    assertTrue("returned point is not 3D: " + point, point.length() == 3);
    double lon = point.getDouble(0);
    double lat = point.getDouble(1);
    double ele = point.getDouble(2);
    assertTrue("nearest point wasn't correct: lat=" + lat + ", lon=" + lon + ", ele=" + ele,
            lat == 43.73070006215647 && lon == 7.421392181993846 && ele == 66.0);
}

From source file:com.graphhopper.http.NearestServletWithEleIT.java

@Test
public void testWithoutEleQuery() throws Exception {
    JSONObject json = nearestQuery("point=43.730864,7.420771&elevation=false");
    assertFalse(json.has("error"));
    JSONArray point = json.getJSONArray("coordinates");
    assertTrue("returned point is not 2D: " + point, point.length() == 2);
    double lon = point.getDouble(0);
    double lat = point.getDouble(1);
    assertTrue("nearest point wasn't correct: lat=" + lat + ", lon=" + lon,
            lat == 43.73070006215647 && lon == 7.421392181993846);

    // Default elevation is false        
    json = nearestQuery("point=43.730864,7.420771");
    assertFalse(json.has("error"));
    point = json.getJSONArray("coordinates");
    assertTrue("returned point is not 2D: " + point, point.length() == 2);
    lon = point.getDouble(0);//from w w w.  java  2 s .c  o m
    lat = point.getDouble(1);
    assertTrue("nearest point wasn't correct: lat=" + lat + ", lon=" + lon,
            lat == 43.73070006215647 && lon == 7.421392181993846);
}

From source file:reittienEtsinta.tiedostonKasittely.GeoJsonLukija.java

public Reitti lueReitti(File tiedosto) {
    JSONObject obj = this.lataaJsonObject(tiedosto);
    JSONArray arr = obj.getJSONArray("features");

    double[] lat = new double[arr.length()];
    double[] lon = new double[arr.length()];
    int[] aika = new int[arr.length()];

    for (int i = 0; i < arr.length(); i++) {
        JSONArray piste = arr.getJSONObject(i).getJSONObject("geometry").getJSONArray("coordinates");
        lat[i] = piste.getDouble(1);
        lon[i] = piste.getDouble(0);//  w w  w.  jav a2s  .  c o m

        String aikaString = arr.getJSONObject(i).getJSONObject("properties").getString("time");

        DateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss", Locale.ENGLISH);
        Date timestamp = null;
        try {
            timestamp = format.parse(aikaString);
        } catch (ParseException ex) {
            System.out.println("format ex");
        }
        int sekunnit = (int) timestamp.getTime() / 1000;
        aika[i] = sekunnit;

    }
    Reitti reitti = new Reitti(lon, lat, aika);
    return reitti;
}

From source file:com.jennifer.ui.util.ColorUtil.java

private static JSONObject parseAttr(String type, String direction) {
    JSONObject o = new JSONObject();

    if (GRADIENT_LINEAR.equals(type)) {
        if ("".equals(direction)) {
            direction = LEFT;/*from   w w  w.  j av a 2  s.c o m*/
        }

        o.put("direction", direction);

        if (LEFT.equals(direction)) {
            o.put("x1", 0).put("y1", 0).put("x2", 1).put("y2", 0);
        } else if (RIGHT.equals(direction)) {
            o.put("x1", 1).put("y1", 0).put("x2", 0).put("y2", 0);
        } else if (TOP.equals(direction)) {
            o.put("x1", 0).put("y1", 0).put("x2", 0).put("y2", 1);
        } else if (BOTTOM.equals(direction)) {
            o.put("x1", 0).put("y1", 1).put("x2", 0).put("y2", 0);
        } else if (TOP_LEFT.equals(direction)) {
            o.put("x1", 0).put("y1", 0).put("x2", 1).put("y2", 1);
        } else if (TOP_RIGHT.equals(direction)) {
            o.put("x1", 1).put("y1", 0).put("x2", 0).put("y2", 1);
        } else if (BOTTOM_LEFT.equals(direction)) {
            o.put("x1", 0).put("y1", 1).put("x2", 1).put("y2", 0);
        } else if (BOTTOM_RIGHT.equals(direction)) {
            o.put("x1", 1).put("y1", 1).put("x2", 0).put("y2", 0);
        } else {
            String[] arr = direction.split(DIRECTION_SPLITTER);

            if (arr.length == 4) {
                JSONArray list = new JSONArray();
                for (int i = 0, len = arr.length; i < len; i++) {
                    list.put(i, arr[i]);
                }

                o.put("x1", list.getDouble(0)).put("y1", list.getDouble(1)).put("x2", list.getDouble(2))
                        .put("y2", list.getDouble(3));
            }
        }
    } else {
        String[] arr = direction.split(DIRECTION_SPLITTER);
        JSONArray list = new JSONArray();
        for (int i = 0, len = arr.length; i < len; i++) {
            list.put(i, arr[i]);
        }

        o.put("cx", list.getDouble(0)).put("cy", list.getDouble(1)).put("r", list.getDouble(2))
                .put("fx", list.getDouble(3)).put("fy", list.getDouble(4));
    }

    return o;
}

From source file:com.jennifer.ui.util.scale.OrdinalScale.java

public Scale rangePoints(JSONArray interval, int padding) {

    JSONArray domain = domain();/*w  ww.j  a  v  a2 s .  c  o  m*/
    JSONArray range = new JSONArray();

    double start = interval.getDouble(0);
    double end = interval.getDouble(1);

    int step = domain.length();
    double unit = (end - start - padding) / step;

    for (int i = 0, len = domain.length(); i < len; i++) {
        if (i == 0) {
            range.put(Double.valueOf(start + padding / 2 + unit / 2));
        } else {
            range.put(range.getDouble(i - 1) + unit);
        }
    }

    this.range(range);
    _rangeBand = unit;
    return this;
}

From source file:com.jennifer.ui.util.scale.OrdinalScale.java

public Scale rangeBands(JSONArray interval, int padding, int outerPadding) {

    JSONArray domain = domain();/* w  ww  . j a  v  a2  s  .c  o m*/
    JSONArray range = new JSONArray();

    int count = domain.length();
    int step = count - 1;

    double start = interval.getDouble(0);
    double end = interval.getDouble(1);

    double band = (end - start) / step;

    for (int i = 0, len = domain.length(); i < len; i++) {
        if (i == 0) {
            range.put(start);
        } else {
            range.put(band + range.getDouble(i - 1));
        }
    }

    this.range(range);
    _rangeBand = band;

    return this;
}

From source file:com.shearosario.tothepathandback.DisplayDirectionsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_directions);

    getActionBar().setDisplayHomeAsUpEnabled(true);

    Intent intent = getIntent();/*from   w  w  w .java2s  . com*/

    /*if(intent.hasExtra("origin"))
    {
       double[] temp = intent.getDoubleArrayExtra("origin");
       origin = new LatLng (temp[0], temp[1]);
    }
    if (intent.hasExtra("destination"))
    {
       double[] temp = intent.getDoubleArrayExtra("destination");
       destination = new LatLng (temp[0], temp[1]);
    }*/

    String linkCollection = null;
    String nodeCollection = null;
    String points = null;

    if (intent.hasExtra("GuidanceLinkCollection"))
        linkCollection = intent.getStringExtra("GuidanceLinkCollection");
    if (intent.hasExtra("GuidanceNodeCollection"))
        nodeCollection = intent.getStringExtra("GuidanceNodeCollection");
    if (intent.hasExtra("shapePoints"))
        points = intent.getStringExtra("shapePoints");

    gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.directionsView)).getMap();
    gMap.setMyLocationEnabled(false);
    gMap.setBuildingsEnabled(false);
    gMap.getUiSettings().setZoomControlsEnabled(false);

    TextView textView = (TextView) findViewById(R.id.osm_guidance);
    textView.setText(Html.fromHtml("Data provided by  OpenStreetMap contributors "
            + "<a href=\"http://www.openstreetmap.org/copyright\">License</a>"));
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    textView = (TextView) findViewById(R.id.guidance_text);
    textView.setText(
            Html.fromHtml("Guidance Courtesy of " + "<a href=\"http://www.mapquest.com\">MapQuest</a>"));
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    PolylineOptions rectOptions = new PolylineOptions();
    markers = new ArrayList<Marker>();

    try {
        JSONArray jGuidanceLinkCollection = new JSONArray(linkCollection);
        JSONArray jGuidanceNodeCollection = new JSONArray(nodeCollection);
        JSONArray jShapePoints = new JSONArray(points);

        int lastIndex = 0;

        for (int i = 0; i < jGuidanceNodeCollection.length(); i++) {
            JSONObject nodeObject = jGuidanceNodeCollection.getJSONObject(i);
            JSONArray linkIds = nodeObject.getJSONArray("linkIds");

            int linkIndex = 0;
            if (linkIds.length() != 0)
                linkIndex = linkIds.getInt(0);
            else
                continue;

            JSONObject linkObject = jGuidanceLinkCollection.getJSONObject(linkIndex);
            int shapeIndex = linkObject.getInt("shapeIndex");

            // The index of a specific shape point is i/2, so multiply by 2 to get the beginning index in shapePoints
            // evens are lat and odds are lng
            double lat = jShapePoints.getDouble((shapeIndex * 2));
            double lng = jShapePoints.getDouble((shapeIndex * 2) + 1);

            lastIndex = ((shapeIndex * 2) + 1);

            if (i == 0) {
                Marker temp = gMap
                        .addMarker(new MarkerOptions().position(new LatLng(lat, lng)).title("Origin"));
                markers.add(temp);
            } else if (nodeObject.isNull("infoCollection") == false) {
                Marker temp = gMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng))
                        .title(nodeObject.getJSONArray("infoCollection").getString(0)));
                markers.add(temp);
            }
        }

        for (int i = 0; i < lastIndex; i++) {
            double lat = jShapePoints.getDouble(i);
            i++;
            double lng = jShapePoints.getDouble(i);

            rectOptions.add(new LatLng(lat, lng));
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    gMap.addPolyline(rectOptions);

    markersIndex = 0;

    gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(markers.get(markersIndex).getPosition(), 17));
    markers.get(markersIndex).showInfoWindow();

    gMap.setOnMarkerClickListener(new OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker arg0) {
            if (arg0 != null) {
                for (int i = 0; i < markers.size(); i++) {
                    if (markers.get(i).equals(arg0)) {
                        markersIndex = i;
                        break;
                    }
                }

                if (markersIndex == 0) {
                    findViewById(R.id.button_nextStep).setEnabled(true);
                    findViewById(R.id.button_previousStep).setEnabled(false);
                } else if (markersIndex == (markers.size() - 1)) {
                    findViewById(R.id.button_nextStep).setEnabled(false);
                    findViewById(R.id.button_previousStep).setEnabled(true);
                } else {
                    findViewById(R.id.button_nextStep).setEnabled(true);
                    findViewById(R.id.button_previousStep).setEnabled(true);
                }

                gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(arg0.getPosition(), 17));

                arg0.showInfoWindow();

                return true;
            }

            return false;
        }
    });
}