Realtime Maps with Mapbox + Firebase + Angular

Fireship · Beginner ·🛠️ AI Tools & Apps ·9y ago

Key Takeaways

This video demonstrates how to build a realtime map feature using Mapbox, Firebase, and Angular, allowing users to post messages on a map with specific GPS coordinates and view them in real-time.

Full Transcript

realtime map features are part of some of the most successful apps in the world such as Uber ways and Pokémon go in this episode I'm going to show you how to start building your own real-time map features using the mapbox API with angular 4 on the front end and Firebase on the back end the demo you're looking at here allows users to post messages on the map that are associated with specific GPS coordinates then the user can click on the message and fly to wherever those GPS coordinates happen to be the important thing to notice here is that the data in Firebase and the map are staying in sync in real time so any user observing this map will have access to the latest data as soon as it's saved to the Firebase database before we get into the code I want to share a helpful tutorial from West Doyle he spends a full hour building a RunKeeper inspired angular 4 app which is a great resource if you're working with mapbox you can find the link in the description below the first step is to sign up for a free mapbox account and then retrieve your API access token during the initial setup mapbox should give you a link to the CSS that you can include in the index.html file and then you'll want to add your access token to your environment file then you can run npm install mapbox DGL mapbox has some good default Maps out of the box but you can customize them to an infinite number of combinations in this case I'm using the cogram app to mimic the color pattern in an image then you can use the mapbox editor to customize all the finer details Within in the map one thing that's really important when working with any geolocation data is to make sure it follows a consistent format in this example we're going to create a typescript interface to ensure that it follows the geojson spec geolocation data is often shared between multiple platforms so we want to make sure our app is following the same spec that every other API is going to follow the most important aspect here is the geometry which is just the GPS coordinates of a given location we're also going to create a feature collection class which is is part of the geojson spec and it's essentially just an array of geojson data now we can start building the service the service is going to serve two purposes first it will initialize the map with the API key and it will also handle all the data retrieval and updating with Firebase so we import the angular fire database as well as our geojson class and the mapbox GL library then we can add the access token from our environment to mapbox and the Constructor the get markers method will just return a Firebase list observable and then when we create a marker it'll have our gojon format and it will go to the markers list and lastly we add a method to remove a marker now we can build the component there's going to be a lot going on here so I recommend pausing the video or checking out the full lesson on angular firebase.com to really get a full grasp of everything after importing the mapbox library and our map service we defined a variable for the map itself then add some default values for the map style and the latitude and longitude The Source variable will be the live connection with mapbox and the markers will supply the data that updates that Source we inject the service in the Constructor and then retrieve the markers from Firebase during NG on a knit then we'll initialize the map but first let's check out the HTML we have a div with an ID of map this div will be replaced with the contents the map itself then we Loop over all the markers in the database when the user clicks on a marker it'll fly to that location on the map and they also have the option to remove a marker and the last thing we'll do is add a text input for the user to enter the message they want placed on the map this will just be bound to the message variable with NG model so the end result is the user types in a message clicks the map and that appears on the message as well as being saved to Firebase then any user observing this data can click it and it'll fly to that exact location so now back in the typescript when we ini initialize a map we want to figure out the user's location if possible and center the map on their exact location if we can we do that by calling Navigator geolocation and that'll give us a promise and when that promise returns it should have the coordinates of that user then we can use the fly to Method from mapbox to fly to that location to define the map variable we call the map class and pass some configuration options to it the container corresponds to the div with an ID of map in the HTML mapbox also has a bunch of optional parameters you can pass here so check those out in the documentation you can also add additional features to the app here we add some additional navigation controls in addition to that you can register event listeners here we listen for the click event which will return the GPS coordinates of wherever that user clicked so we can then use that to update the Firebase database first we convert it to geojson format and then we add an optional message parameter that's the message the user enters in the form and then we send that to the Firebase database so at this point we just need to connect this real-time data stream with the map itself when it's finished loading it'll trigger the load event and then we can start connecting that stream so we call add Source on the map with the name of Firebase and just pass it in empty geojson feature collection then we can set the source as a variable on the component itself to start feeding data to the source we subscribe to the markers observable then we convert the data to a future collection and call set data on the source that will push the latest data to the end user viewing the map at this point we just need to Define some styling for the markers themselves mapbox has a very large API for defining all these Styles so you can pretty much customize them to look any way you want you can also interpolate any data that was added to the properties field of the geojson itself which we're doing here with the message with single curly braces and now just to wrap this up we'll add a couple of helper methods to remove markers as well as fly to various locations on the map now we should be able to type in the text and then add it to the map by clicking on whatever location we want and have everything updated in real time that's it for realtime maps with mapbox if this video helped you please like And subscribe and if you want to support the channel consider becoming a pro subscriber at angular firebase.com you can talk to me directly on our slack team and I'll help you figure out whatever custom map integration you're going for thanks for watching and I'll see you next [Music] time

Original Description

In this lesson, we connect realtime data from Firebase to Mapbox GL in Angular4. My goal is to give you a starting point for building realtime map features like those found Uber, Waze, and Pokemon GO. Checkout Wes Doyle's Angular4 GPS Tutorial: https://youtu.be/EHdSb279Lzg Full lesson at https://angularfirebase.com/lessons/build-realtime-maps-in-angular-with-mapbox-gl/ Get Mapbox API credentials at https://www.mapbox.com/
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Fireship · Fireship · 33 of 60

1 Angular 4 Development and Production Environments with Firebase
Angular 4 Development and Production Environments with Firebase
Fireship
2 OAuth with Angular and Firebase Tutorial
OAuth with Angular and Firebase Tutorial
Fireship
3 Anonymous Authentication with Angular and Firebase - Lazy Registration
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
4 Angular Router Guards for Firebase Users
Angular Router Guards for Firebase Users
Fireship
5 Angular Firebase CRUD App with NoSQL Database Tutorial
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
6 Upload Files from Angular to Firebase Storage
Upload Files from Angular to Firebase Storage
Fireship
7 How to Deploy an Angular App to Firebase Hosting
How to Deploy an Angular App to Firebase Hosting
Fireship
8 Sharing Data between Components in Angular
Sharing Data between Components in Angular
Fireship
9 Loading Spinners for Asynchronous Firebase Data
Loading Spinners for Asynchronous Firebase Data
Fireship
10 Angular 4 Transactional Email with Google Firebase Cloud Functions
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
11 Firebase Database Rules Tutorial
Firebase Database Rules Tutorial
Fireship
12 Autocomplete Search with Angular4 and Firebase
Autocomplete Search with Angular4 and Firebase
Fireship
13 Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
14 Angular Drag-and-Drop File Uploads to Firebase Storage
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
15 Text Translation with Firebase Cloud Functions onWrite and Angular 4
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
16 Custom Usernames with Firebase Authentication
Custom Usernames with Firebase Authentication
Fireship
17 Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
18 Simple Pagination with Firebase and Angular 4
Simple Pagination with Firebase and Angular 4
Fireship
19 How to Connect Firebase Users to their Data - 3 Methods
How to Connect Firebase Users to their Data - 3 Methods
Fireship
20 Add Toast Message Notifications to your Angular App
Add Toast Message Notifications to your Angular App
Fireship
21 Facebook-Inspired Reactions System with Angular and Firebase
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
22 Learn NgModule in Angular with Examples
Learn NgModule in Angular with Examples
Fireship
23 Lazy Loading Components in Angular 4
Lazy Loading Components in Angular 4
Fireship
24 Stripe Checkout Payments with Angular and Firebase - Part 1
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
25 Process Stripe Payments with Firebase Cloud Functions - Part 2
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
26 Selling Digital Content in Angular with Stripe Payments - Part 3
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
27 Angular 4 Full Text Search with Algolia - Part 1
Angular 4 Full Text Search with Algolia - Part 1
Fireship
28 Algolia with Firebase Cloud Functions - Part 2
Algolia with Firebase Cloud Functions - Part 2
Fireship
29 Firebase Phone Authentication in Angular 4
Firebase Phone Authentication in Angular 4
Fireship
30 Top 7 RxJS Concepts for Angular Developers
Top 7 RxJS Concepts for Angular Developers
Fireship
31 Learn Angular Animations with 5 Examples
Learn Angular Animations with 5 Examples
Fireship
32 Advanced Firebase Data Filtering (Multi-Property)
Advanced Firebase Data Filtering (Multi-Property)
Fireship
Realtime Maps with Mapbox + Firebase + Angular
Realtime Maps with Mapbox + Firebase + Angular
Fireship
34 Angular Reactive Forms with Firebase Database Backend
Angular Reactive Forms with Firebase Database Backend
Fireship
35 Send Push Notifications in Angular with Firebase Cloud Messaging
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
36 Top 7 Ways to Debug Angular 4 Apps
Top 7 Ways to Debug Angular 4 Apps
Fireship
37 Infinite Scroll with Angular and Firebase
Infinite Scroll with Angular and Firebase
Fireship
38 Use TypeScript with Firebase Cloud Functions
Use TypeScript with Firebase Cloud Functions
Fireship
39 Realtime Graphs and Charts with Plotly and Firebase
Realtime Graphs and Charts with Plotly and Firebase
Fireship
40 Role-Based User Permissions in Firebase
Role-Based User Permissions in Firebase
Fireship
41 User Presence System in Realtime - Online, Offline, Away
User Presence System in Realtime - Online, Offline, Away
Fireship
42 Location-based Queries with GeoFire and Angular Google Maps
Location-based Queries with GeoFire and Angular Google Maps
Fireship
43 Angular ngrx Redux Quick Start Tutorial
Angular ngrx Redux Quick Start Tutorial
Fireship
44 Angular Ngrx Effects with Firebase Database
Angular Ngrx Effects with Firebase Database
Fireship
45 Progressive Web Apps with Angular
Progressive Web Apps with Angular
Fireship
46 Angular Ngrx with Firebase Google OAuth User Authentication
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
47 RxJS Quick Start with Practical Examples
RxJS Quick Start with Practical Examples
Fireship
48 Send SMS Text Messages with Twilio and Firebase
Send SMS Text Messages with Twilio and Firebase
Fireship
49 Firebase Database Performance Profiling
Firebase Database Performance Profiling
Fireship
50 Native Desktop Apps with Angular and Electron
Native Desktop Apps with Angular and Electron
Fireship
51 Subscription Payments with Stripe, Angular, and Firebase
Subscription Payments with Stripe, Angular, and Firebase
Fireship
52 Firestore with AngularFire5 Quick Start Tutorial
Firestore with AngularFire5 Quick Start Tutorial
Fireship
53 Angular HTTP Client Quick Start Tutorial
Angular HTTP Client Quick Start Tutorial
Fireship
54 Google Sign-In with Firestore Custom User Data
Google Sign-In with Firestore Custom User Data
Fireship
55 Star Review System from Scratch with Firestore + Angular
Star Review System from Scratch with Firestore + Angular
Fireship
56 Angular Chatbot with Dialogflow (API.ai)
Angular Chatbot with Dialogflow (API.ai)
Fireship
57 Learn @ngrx/entity and Feature Modules
Learn @ngrx/entity and Feature Modules
Fireship
58 Infinite Scroll Pagination with Firestore
Infinite Scroll Pagination with Firestore
Fireship
59 Faster Firestore via Data Aggregation
Faster Firestore via Data Aggregation
Fireship
60 Contentful - CMS for Angular Progressive Web Apps
Contentful - CMS for Angular Progressive Web Apps
Fireship

This video teaches how to build a realtime map feature using Mapbox, Firebase, and Angular, and provides a starting point for building similar features like those found in Uber, Waze, and Pokemon GO.

Key Takeaways
  1. Sign up for a Mapbox account and retrieve the API access token
  2. Install Mapbox GL and add the access token to the environment file
  3. Create a TypeScript interface to ensure geolocation data follows the GeoJSON spec
  4. Build a service to initialize the map and handle data retrieval and updating with Firebase
  5. Build a component to display the map and handle user interactions
  6. Connect the realtime data stream with the map itself
💡 To build a realtime map feature, it's essential to ensure that geolocation data follows a consistent format, such as the GeoJSON spec, and to use a service to handle data retrieval and updating with the backend.

Related Reads

Up next
How to Get Your Brand Cited by ChatGPT, Claude and Gemini
Arvow
Watch →