Passing arguments to function

Penny Pang
Graduation Thesis 2019
2 min readNov 3, 2019

As mentioned in my previous blog post, I managed to code the API function with all the parameters separately. In my App.js file, I would have all my API call and render.

Here is my API function

This is all the parameters from the trip API being called in const api_call = "trip" and for the parameters name_origin this is where we pass in the user’s geolocation coordinates latitude and longitude in EPSG:4326 format.

Getting user geolocation

In the previous blog, I went through how to get the user’s geolocation with Geolocation MDN function

latlng will return all the coordinates and I will be storing that into a state myCoord in the this.setState . Make sure you initialise the state in the constructor method. Now that the user’s geolocation coordinates is stored in a state and we can use it anywhere!

Note: If you want to check whether the geolocation function is working, use console.log(latlng) to print out user’s geolocation

Putting myCoord into trip API parameter

Back to the file where I am putting the trip API parameters, since it is a function, you can pass in myCoord state into the input parameters and then in the parameters, name_origin: myCoord should have the user’s geolocation. This is similar to what we did with the stopID

--

--

Penny Pang
Graduation Thesis 2019

Full-time UX/UI Designer, Part-time online entrepreneur, Casual food blogger and innovation advocate