Skip to content

Reusable text autocomplete which consumes an API call in React.js. Response is then sent to MapBox Geocoding API for latitude and longitude and returned in Mapbox-gl-js for location display inside map display.

License

Notifications You must be signed in to change notification settings

DanBurbach/MapBox_AutoComplete_React.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MapBox AutoComplete React.js Project

AutoCompleteJS Main Page

This project was bootstrapped with Create React App.

Created by Dan Burbach

February 2020

Description

Coding exercise to create a reusable autocomplete component using JavaScript. This component will consume
a remote web service (API to JSON) that provides a list of Places. Each Place is comprised of an ID, name, description,
tags, and a description match field which gives information about the substring in the description that
matches the provided query. Upon selecting a suggestion, the state of the component should be updated to
reflect the selected location.
 
Furthermore... the location data is stored in state, followed by running it through Mapbox Geocoder which
provides a latitude and longitude in its returned JSON (via secondary API). This is stripped out and added to the MapBox
component, re-renders the map, and displays the searched for location.

Dataflow

  • User enters in text field a location and triggers and onChange function which enters the Users Input into an API fetch.
  • The returned data is turned into a JSON and then stripped of unneeded information and amended onto a ul as an li.
  • The 5 returned list items are then displayed in a drop-down box below the text field.
  • Upon selection (either by clicking with a mouse, or by selecting with keyboard) the state is saved and sent to the MapBox upon Submission.
  • Submitted location is then passed via props and sent through another API library for Geocoding and - much like before - turned into a JSON, stripped for latitude and longitude, and passed onto a mapping API.
  • The mapping API takes the coordinates and processes them, returning a new map and location on componentDidUpdate. Rendering in a map, and displaying coordinates for the user. Dataflow_Whiteboard

Setup/Installation Requirements

  • Clone repository

  • Open terminal

  • Run npm install

  • Include an API Key from MapBox (included temporarily in this project - will be removed)

  • npm run start

  • Open a browser: http://localhost:3000/

  • Enjoy!

AutoCompleteJS_Working_Example

Technologies Used

React.js, CSS3, HTML5, Javascript, Postman, MapBox, and a provided coding challenge API Location Library

-MapBox- Maps and location for developers. Precise location data and powerful developer tools to change the way we navigate the world. In this project it is used for both the display of the map via API call, AND provides Geo Mapping of the locations provided - which provides latitude and longitude coordinates.

Bugs

  • When typing too fast, the API libraries cannot keep up and errors are thrown.
  • If deleting what was typed and there isn't anything in the text box an error is thrown (amended temporarily with the Reset Button). (Fix: Display pop-up error)
  • Some entered letters and returns search recommendations do not have a map return and are found to throw an error. (Fix: Update API call to capitalize the entire requested data. Example: "egypt" would return an error, but "Egypt" wouldn't)

Future Development

  • Smoother API Calls
  • Alternative Map Source
  • Mobile Friendly
  • Dark Mode
  • Larger Map

Version

Beta v1.0

License(s)

Working Code is Licensed under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright 2020 Daniel Burbach

About

Reusable text autocomplete which consumes an API call in React.js. Response is then sent to MapBox Geocoding API for latitude and longitude and returned in Mapbox-gl-js for location display inside map display.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published