Exploring MapQuest API: Unraveling the process of dissecting MapQuest

I am currently exploring MapQuest navigation and utilizing JavaScript code to retrieve the data.

Although I am able to extract JSON content in my application, I am unsure of how to utilize this data for navigation. I have started a new project and executed the code.

class jsonapp extends AsyncTask<String, Void, String>{

@Override
protected String doInBackground(String... uri) {
    // TODO Implement the method...

I am aiming to create a narrative-style navigation system. Any guidance on how to achieve this?

Am I on the right track with my approach?

Thank you in advance for your help.

Answer №1

I have personally found success with this method:

For the route matrix, I followed a similar approach that you can also try for your specific route.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLEncoder;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;

public class ApacheHttpClientGet {

    static DefaultHttpClient httpClient = new DefaultHttpClient();
    static HttpGet getRequest;
    static HttpResponse response;

    public static void main(String[] args) {
        try {

            getRequest = new HttpGet("http://www.mapquestapi.com/directions/v2/routematrix?key=XFZxlqQQJbNaABkGXuaRfUHSIdYXuIBh&.format(lat,long)&inFormat=kvp&outFormat=json&from=BuddhdaveColony,vadodara,gujarat&to=oldpadraroad,vadodara,gujarat&unit=k");

            response = httpClient.execute(getRequest);

            if (response.getStatusLine().getStatusCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + response.getStatusLine().getStatusCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (response.getEntity().getContent())));

            String output;
            String jsonData="";
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                jsonData += output + "\n";
                System.out.println(jsonData);
            }

            JSONObject obj = new JSONObject(jsonData);
            System.out.println("allToAll: " + obj.getBoolean("allToAll"));
            System.out.println("distance: " + obj.getJSONArray("distance"));

            httpClient.getConnectionManager().shutdown();

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
                e.printStackTrace();
        }
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expanding the width of Material UI Javascript Dialog Box

Currently, I am utilizing the dialog feature from Material UI in my React JS project and I am looking to expand its width. After some research, I discovered that there is a property called maxWidth which allows you to adjust the width of the dialog. Howe ...

the click event fails to trigger when the id or class is modified

Hey there, I'm new to working with jquery and I've encountered a problem. Here's the code snippet: http://jsfiddle.net/8guzD/ $('#test.off').click(function(){ $(this).removeClass('off').addClass('on'); }) ...

Which sensor is most effective for detecting motion?

Currently, I am developing an Android app that can track human movements such as FRONT, BACK, RIGHT, and LEFT. For example, if your phone is facing you and you move it to the left, the X-axis should register negative values, while moving it up should resul ...

I'm feeling completely lost trying to understand cors in conjunction with fetch, particularly when an options request is

I am using whatwg fetch in the code snippet below: const headers = new Headers(); //uncommenting this causes the preflight options request to be sent //headers.append('x-something', 'foo'); const response = await fetch(&apos ...

Converting multiple WordPress plugins into a single JSON option

Having a plugin with numerous options, I am utilizing an angular application on the frontend to display them all. In order to store these options in the database as JSON data, I need to ensure that all 10 options are saved within a single row in the wp_opt ...

Troubleshooting jQuery compatibility issue in IE6 when using javascript and loading content through ajax

Encountering issues with IE6 and javascript applied to ajax content. Unable to use any type of javascript (plain or with jQuery) on the ajax-retrieved content. The main html page loads the Header content using ajax (specifically utilizing the jQuery ...

Executing a function when a webpage loads in Javascript

I have created a responsive website using Twitter Bootstrap. On my site, I have a video displayed in a modal that automatically plays when a button is clicked. Instead of triggering the function with a button click, I want the function to be called when ...

Unable to access properties of an unknown item (reading 'remove')

Can you provide guidance on how to remove the top-level parent element of a div? I've been attempting to delete the main parent element of a specific div. element.innerHTML = ` <div class="postIt-item"> <div class="postIt-item-btn ...

When using NodeJS with expressJS, remember that req.body can only retrieve one variable at a

I'm having trouble with my login and signup pages. The login page is working correctly, but the signup page is only transferring the password for some reason. App.JS: var express = require("express"); var app = express(); var bodyParser = require("bo ...

What is the proper way to integrate three.js (a third-party library) into the view controller of an SAPUI5 application

Seeking a Solution Is there a way to integrate the three.js library into SAPUI5 in order to access it using THREE as the root variable in my main view controller? I attempted to create a directory named libs within my project folder and include it in the ...

working with JSON variables in Swift

Hello, I am new to Swift and programming. I am trying to work with JSON data but having trouble understanding it. Here is a snippet of the JSON I am working with: { "nextUpdate":300, "subscriptions":["speedon","roamLikeHome","tns"], "title":"", "hasOffer ...

Using node.js to parse an XML file from a URL and iterate through it to retrieve all the URLs contained within

I am currently utilizing the node module xml2js. The format of my xml file looks like this: <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet type="text/xsl"?> <?xml-stylesheet type="text/css" media="screen" href="some url" ?> ...

Sort arrays in Javascript by their respective lengths

Is there a way to arrange these arrays in descending order of the number of items they contain? I believe the logic is correct, but I might be missing some essential methods. The current output is empty. //Declare Variables var TN = ['Chattanooga&apo ...

Unexpected output from the MongoDB mapReduce function

Having 100 documents stored in my mongoDB, I am facing the challenge of identifying and grouping possible duplicate records based on different conditions such as first name & last name, email, and mobile phone. To achieve this, I am utilizing mapReduc ...

Issue with IE due to jQuery/JavaScript conflict

After selecting one of the two radio buttons, I want to increment the total by $10. If the other option is selected, I want to revert back to the original total price. The jQuery function I am currently using is as follows: function check_ceu() { var ...

What is the best method for regularly importing large JSON datasets into Cloud Firestore?

I have a task to import a large JSON file containing 180k records. Currently, I am able to upload only 500 records per run using the code below, but I need to find a way to efficiently upload all 180k records periodically. My Objectives: Successfully par ...

Is there an alternative method to load a webpage with a large amount of POST data if the form POST function is not functioning properly with a massive JSON string?

I'm in the process of implementing a form to load a page with Post data. The post data consists of a large string, and I am uncertain if its length is causing any issues. The scenario involves a search page redirecting to a results page, which takes ...

Angular: Discovering and retrieving all images within a div container

I am on a quest to locate all image tags within a specific div. These image tags are nested within paragraph tags inside the div. I attempted to create a plunkr to accomplish this task, but unfortunately, I haven't had any success yet. If anyone is ab ...

Transmitting a sequence of JSON information from php to JavaScript,

I am struggling to fetch a series of JSON data from PHP to my JavaScript file. Initially, I have multiple JSON data stored in an array in PHP, and I am echoing each one by looping through the array in my JavaScript file. <?php $result = array('{ ...

Utilizing a JSON API to link to various elements simultaneously

In my current work on a UWP project, I am utilizing a SQL database to store values and a Json API to retrieve these values from the database into Visual Studio. At present, I am successfully accessing the values and storing them in c# variables without an ...