fetch()
The tag
fetch()
will execute the API based on this link
(this.locationEndpoint + userIPData.ip)
. If the call is works, then it will return the data object as a json and it will have long, lat, city, and state properties which we assign to corresponding properties in our classLocationFromIP
.When we render html, these properties will be used as values for input box, google maps link, and Wikipedia search parameters.
API
- This API https://freegeoip.app/json/ requires concatenating the link with IP address and fetching the returning data object. Here is where you can learn more about Wikipedia API.
- For my project, the API doesn't work and returns nothing, so I had to hardcode the properties to show how the website would look if the API would work. This link https://freegeoip.app/ says you need to obtain API key, which needs to be added to the end of the API call.
Wikipedia-query
Wikipedia-query is very simple. All that's needed to do is pass values for the search parameters.
Interestingly, passing State College as a parameter doesn't generate any return for just city, but adding the state helps.
My Work
- Here is where you can see my work and look more into the code.
Top comments (0)