Como mostrar endpoint no maps pelo get? - javascript

Asked

Viewed 89 times

2

I am new to programming and I am developing an app from which I search for a list of taxis closer to my location through a website. But I’m having a hard time with it.

Lists active taxi drivers within an Endpoint geographical rectangle:

GET https://api.99taxis.com/lastLocations

Parameters:

  • sw: Extreme south point, extreme west of the rectangle, in the form "latitude, longitude". Ex: -23.612474,- 46.702746

  • ne: Northernmost point, easternmost point of the rectangle, in the format "latitude,longitude". Ex: -23.589548,- 46.673392

Example

Request:

GET https://api.99taxis.com/lastLocations?sw=-23.612474,-46.702746&ne=-23.589548,-46.673392

I can only create an endpoint, but I don’t know how to pull this service and put it on the map, for example:

var person = MapModule.createAnnotation({

    latitude: -23.474891,
    longitude: -46.526756,
    title: 'Você',
    subtitle: 'São Paulo, SP',
    pincolor: MapModule.ANNOTATION_RED,
    image:"/ui/images/buscador.png",
}); 

Could someone help me with the line of codes for me to pick up the latidude and longitude of these taxis in this rectangular geography??? Thanks guys

1 answer

1


Dude, check out jQuery’s $.getJSON(). I usually use it to mess with Apis in general. It will make a request with this url and return a JSON with an array, where each index is a dot. You can go through this array with a for, pass the JSON and to home index take the latitude and longitude keys and create an endpoint on the map.

I did something similar in a codepen a few months ago, just changed the API from where I get the information, but overall it’s just what you need. Take a look, it might help you: http://codepen.io/andresampaio/pen/meeGVE

Thanks

  • André, I downloaded your link and gave me a beautiful whitening... however, I’m still struggling in the for... you accessed the link of locations? So, I’m not able to go through this array with a for and take the index of the latitude and longitude keys and houses... I also need that driverId but knowing the location I will be able to execute it. Could you help me with that?

  • It is very strange, but I checked the headers and etc and the server response is there, in a JSON, straight, but when I use some function, be the $.ajax or the $.getJSON, the answer does not come, neither in text nor in JSON, I do not know if it is the API that is blocking. I couldn’t manipulate any information, even though the answer exists.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.