bigscal-logo
  • bigscal-logo
  • Services
    • Software Development
          • Software Product Development
            • SaaS Consulting
            • MVP Development
            • Startup Product Development
            • Product UI/UX Design
            • Startup Consulting
          • Information Technology Consulting
            • Agile Consulting
            • Software Consulting
            • Data Analytics Consulting
            • CRM Consulting
          • Software Outsourcing
            • IT Staff Augmentation
            • Dedicated Development Teams
            • Shadow Engineers
            • Offshore Software Development
            • Offshore Development Center
            • White Label Services
          • Custom Software Development
            • Enterprise Software Development
            • Nearshore Software Development
          • Digital Transformation
    • Application Development
          • Mobile App Development
            • React Native App Development
            • iPhone app development
            • Android App Development
            • Flutter App Development
            • Cross Platform App Development
            • Xamarin App Development
          • Web Development
            • Website & Portal Development
          • Frontend Development
            • Angular Development
            • React.js Development
            • Next.js Development Services
          • Full Stack Development
            • MEAN Stack Development
            • MERN Stack Development
          • Backend Development
            • .NET Development
            • Node js Development
            • Laravel Development
            • PHP Development
            • Python Development
            • Java Development
            • WordPress Development
            • API Development
            • SharePoint Development
          • Cloud Application Development
            • Serverless Software Development
          • Application Maintenance
          • Application Modernization
    • QA & Testing
          • Penetration Testing
          • Usability Testing
          • Integration Testing
          • Security Testing
          • Automated Testing
          • Regression Testing
          • Vulnerability Assessment
          • Functional Testing
          • Software Performance Testing
          • QA Outsourcing
          • Web Application Testing
          • Software Quality Assurance Testers
          • Mobile App Testing
          • QA Consulting
          • Application Testing
    • eCommerce
          • eCommerce Web Design
          • Ecommerce Consulting
          • Digital Consulting
          • eCommerce Web Development
          • Supply Chain Automation
          • B2C eCommerce
          • B2B Ecommerce
    • Analytics & DevOps
          • Big Data Consulting
          • Business Intelligence Consulting
          • Microsoft Power BI
          • Power BI Implementation
          • DevOps Consulting
          • Amazon AWS
          • Microsoft Azure
    • Generative AI Development Services
          • Agentic AI Services
          • AI-ML Developers
          • Hire AI Developers
          • Machine Learning Developers
          • Deep Learning Development
          • IoT Developers
          • Chatbot Developers
  • Industries
    • Education & eLearning
    • Finance
    • Transportation & Logistics
    • Healthcare
      • Hospital Management Software Development
      • Patient Management Software Development
      • Clinic Management System
      • Telemedicine App Development Solutions
      • EMR Software
      • EHR Software
      • Laboratory Information Management Systems
    • Oil and Gas
    • Real Estate
    • Retail & E-commerce
    • Travel & Tourism
    • Media & Entertainment
    • Aviation
  • Hire Developers
    • Mobile Developers
          • Hire Android App Developers
          • Hire iOS App Developers
          • Hire Swift Developers
          • Hire Xamarin Developers
          • Hire React Native Developers
          • Hire Flutter Developers
          • Hire Ionic Developers
          • Hire Kotlin Developers
    • Web Developers
          • Hire .Net Developers
            • Hire ASP.NET Core Developers
          • Hire Java Developers
            • Hire Spring Boot Developers
          • Hire Python Developers
          • Hire Ruby On Rails Developers
          • Hire Php Developers
            • Hire Laravel Developers
            • Hire Codeigniter Developer
            • Hire WordPress Developers
            • Hire Yii Developers
            • Hire Zend Framework Developers
          • Hire Graphql Developers
    • Javascript Developers
          • Hire AngularJs Developers
          • Hire Node JS Developer
          • Hire ReactJS Developer
          • Hire VueJs Developers
    • Full Stack Developers
          • Hire MEAN Stack Developer
          • Hire MERN Stack Developer
    • Blockchain & Others
          • Hire Blockchain Developers
          • Hire Devops Engineers
          • Hire Golang Developers
  • Blogs
  • Careers
  • Company
    • Our Portfolio
    • About Us
    • Contact
  • Inquire Now
  • Menu Menu
Home1 / Frontend2 / How to Integrate Google Maps With React JS
Master Google Maps with React JS

How to Integrate Google Maps With React JS

August 19, 2022/0 Comments/in Frontend /by Sumit Hinagspure

Quick Summary: This article provides a comprehensive and easy-to-follow guide on integrating Google Maps with React JS, enabling developers to enhance their web applications with powerful mapping functionalities. The step-by-step tutorial covers critical aspects such as obtaining the necessary API key, setting up a React project, installing and configuring the necessary packages, and implementing interactive map components. Following this tutorial, developers can seamlessly incorporate Google Maps into their React JS projects, enabling location-based features and providing a more engaging user experience.

Introduction

We’ll cover one of the most prevalent reasons you wish to include Google Maps with React JS: indicating the address of your business and showing your company address. If you like, you may use this as a place to start for more complex situations.

We’ll need the Google map-react package to assist us in incorporating Google Maps into our React project because it’s tremendously strong and sophisticated. This package contains a component that renders any React component on a Google Map using a tiny set of the Google Maps API. I use it first whenever I want to make a React app that uses Google Maps. It is well-maintained and easy to use.

It is only a sample of what the Google Maps API can do, and you may have additional business requirements. Because this is the most typical use case We’ve found, we’ll develop a contact page with a map indicating the business’s address for this guide. If you need something more complicated, the google-map-React team has offered a set of samples you may go over.

So, read first and decide whether you need professional React.js services.

There are a variety of reasons why you would want to use Google Maps in your React app, and we’ll look at one of the most common ones: showing your company address. If you like, you may use this as a starting point for more complicated scenarios.

Why One Need To Integrate Google Maps

Here are a few reasons why you might consider using Google Maps on your website, and you may approach Outsource ReactJS Services for integrating Google Maps with React.

  • Offer directions to your company’s location.
  • To depict a path to an event (i.e., a concert or conference).
  • To offer real-time updates on the whereabouts of a mailed item.
  • Showcase fascinating locations from across the world.

Requirements for integrating Google Maps into your React application

Setup of a React application

A Google Maps API key (which is entirely free)

You may obtain a free Google Maps API key by following the procedures in the Google Maps documentation. You’ll need to create a billing account to eliminate the limits and watermarks that come with it..

Google Maps integration in React

To be clear, we will not go into all of the contact page code because this blog focuses on integrating Google Maps into a React project. The stages we’ll take are as follows:

  1. To hold the map, create a React component (Map.jsx)
  2. To mark the address on the map, create a new React component (LocationPin.jsx)

Map.jsx

mkdir src/components/map && touch src/components/Map.jsx
Use the command above to create a new file in the /components folder. In the following section, We’ll create the map’s code element and the address pin. However, we must first install the google-map-react package using the command: before we can start writing code.

yarn add google-map-react
After installing the software, we will also want our corporate address coordinates. It entails a fast Google search for your company’s longitude and latitude information. I quickly searched using Google’s Amphitheater address and came up with the following results:

const location = {
            address: '1600 Amphitheatre Parkway, Mountain View, california.',
            lat: 37.42216,
            lng: -122.08427,
            }

Of course, the figures for your address will be different. As demonstrated above, we save the data in the object and provide them to the Map component so that we can draw a pin on the map. To summarise, you’ll require the following information:

API Key for Google Maps
Installed google-map-react
Values for longitude and latitude for your company address

We can begin putting up the Map component now that we have all this information. If you want to view the completed code, go to the add-map branch of the repo you cloned earlier, but if you want to learn how to construct it yourself, stick with the tutorial.

Import React, the google-map-package, and the related CSS into src/components/map/Map.jsx as follows:

import React from 'react'
            import GoogleMapReact from 'google-map-react'
            import './map.css'

To implement a Map component that accepts two props, follow these steps:

Create a new Map component that takes in two props:

const Map = ({ location, zoomLevel }) => (
            <div className="map">
            <h2 className="map-h2">Come Visit Us At Our Campus</h2>
            
            <div className="google-map">
            <GoogleMapReact
            bootstrapURLKeys={{ key: '' }}
            defaultCenter={location}
            defaultZoom={zoomLevel}
            >
            <LocationPin
            lat={location.lat}
            lng={location.lng}
            text={location.address}
            />
            </GoogleMapReact>
            </div>
            </div>
            )

Are you able to figure out what the location prop is? It’s the object we made before that stores the location’s address, latitude, and longitude information. The scale of the map when presented on the screen is determined by zoom level, which is an integer ranging from 0 to 20.

You’ll see that the GoogleMapReact component has a child called LocationPin, but it may have many children. The text prop will be rendered on top of the map at the place specified by the lat and long values. In the next step, we’ll make this component.

Check out what GoogleMapReact does with the props it receives:

bootstrapURLKeys is a container for the API key you copied from the Google Console. You can now hardcode the key in this location, but this is not advised for code that will be submitted to GitHub or otherwise made public.

When the map loads for the first time,defaultCenter is merely the middle of the map.

Default zoom determines the map’s initial scale.

This is enough to display a basic map on the screen, but we need to do something extra before we can display this component. The code for LocationPin must be written.

LocationPin

LocationPin

LocationPin

We’d like to be able to draw users’ attention to a particular spot on the map. We can develop an essential component that shows a pin icon and text using Google-map-react, which allows us to render any React component on the map.

I’ll be utilizing a free library of SVG icons called Iconify for the icon. Continue working in the same file and import the following packages as follows:

import { Icon } from '@iconify/react'
            import locationIcon from '@iconify/icons-mdi/map-marker'

Then, as follows, define the LocationPin component:

const LocationPin = ({ text }) => (
            <div className="pin">
            <Icon icon={locationIcon} className="pin-icon" />
            <p className="pin-text">{text}</p>
            </div>
            )
            export default Map

This component, I’m sure, is self-explanatory. LocationPin’s styling is already included in map.css, but you may style it as you like.

All that is left is to export the Map component and add it to the contact page. Please ensure that you export the Map component at the bottom of the file.

Using the Map component

We may use the Map component wherever we want because it is just a React component. Import the Map component into src/App.jsx and place it between ContactSection and DisclaimerSection, as follows:

import React from 'react'
            
            import IntroSection from './components/intro/Intro'
            import ContactSection from './components/contact-section/ContactSection'
            import MapSection from './components/map/Map' // import the map here
            import DisclaimerSection from './components/disclaimer/Disclaimer'
            import FooterSection from './components/footer/Footer'
            
            import './app.css'
            
            const location = {
            address: '1600 Amphitheatre Parkway, Mountain View, california.',
            lat: 37.42216,
            lng: -122.08427,
            } // our location object from earlier
            
            const App = () => (
            <div className="App">
            <IntroSection />
            <ContactSection />
            <MapSection location={location} zoomLevel={17} /> {/* include it here */}
            <DisclaimerSection />
            <FooterSection />
            </div>
            )
            export default App

Now run yarn start in your terminal and browse to localhost:3000 to begin the project. You should see a nice-looking map on your contact page that pinpoints your business address. Isn’t that clever?

Conclusion

To sum it up, combining React JS with Google Maps is the way forward for developers as it allows them to use the powerful location-based features in their web applications. After the step-by-step guide, developers can easily get a Google Maps API key, set up a React project, and integrate the interactive maps in their applications the easiest way. Thus, the integration of the app Google Maps becomes a more pleasing experience for the user and at the same time allows the developers to use the whole services of Google Maps, e.g. geocoding and distance calculations.

Google Maps React is the combination of both of them that allows developers to build applications that are dynamic and responsive that can be used for different purposes, from simple location to complex mapping. Nevertheless, it is significant to be conscious of the possible costs that come with using the Google Maps API after the free tier and developers should check the pricing details to make sure it matches their project’s needs.

FAQ

What is React JS?

React JS is one of the popular JavaScript libraries that are used for building the user interfaces, mostly for web applications. It is the platform where developers can design and build reusable and interactive user interface components that can be used for the sake of the application’s management.

Why should I integrate Google Maps with React JS?

The joining of Google Maps with React JS allows you to add impressive mapping features to your web application, such as a display of locations, geocoding of addresses, a calculation of distances, and an interactive map for a better user experience.

How do I obtain a Google Maps API key?

To obtain a Google Maps API key, you are required to create a project in the Google Cloud Console, activate the Maps JavaScript API, and then generate an API key that is associated with your project. The API generated by this will be useful in understanding how these blended can be used in the project and whether they will work sufficiently.

What packages are commonly in use to integrate Google Maps with React JS?

Some popular packages for integrating Google Maps with React JS are “react-google-maps” and “@react-google-maps/api”. They provide React components that simplify the integration process. When the components are available seamlessly the integration will become much easier as well.

Is there a cost associated with using Google Maps API?

Sure, Google Maps API usage could have expenses that surpass a certain limit of usage. Google has different pricing plans, one of which is the one that is free but has limited usage. The cost details and the way of billing have to be checked and the billing has to be set up to make sure that the API use fits the project’s needs.

Tags: #front-end developer, #frontend, #react.js, Google Maps

You might also like

Explore the blend of ArcGIS API & React Basic Implementation Using ArcGIS API for JavaScript with React
App Innovation Starts Here - Hire React JS Developer Top Reasons to Hire React JS Developer for App Development
Server-Side Rendering in ReactJS How to Set Up Server Side Rendering (SSR) With ReactJS
Boost Business Prospects with A React JS Specialist! Maximizing Your Business Potential with a React JS Developer
React vs. Angular: The Ultimate Battle! Comparison of React vs Angular: Which Is Best in 2024?
Explore the inventive edge of Next.js over React Introduction to Next.js and how it is different from React

Seeking robust and scalable software solutions?

Contact us for industry-leading development services.

Book a 30 min FREE Call

Craft your Best Agile Team

Your Project, Our Expertise - Hire a Developer Now

    Subscribe for
    weekly updates

      privacy-policy I accept the terms and conditions

      Categories

      • AI-ML-Blockchain
      • Aviation
      • Backend
      • Cloud
      • Cross Platform
      • Cyber Security
      • Database
      • DevOps
      • Digital Marketing
      • Ecommerce
      • Education Industry
      • Entertainment Industry
      • Fintech Industries
      • Frontend
      • Full Stack
      • Game Development
      • Healthcare Industry
      • Latest Technology News
      • Logistics Industry
      • Mobile app development
      • Oil And Gas Industry
      • Plugins and Extensions
      • QA & Testing
      • Real Estate Industry
      • SaaS
      • Software Development
      • Top and best Company
      • Travel industries
      • UI UX
      • Website Development

      Table of Content

      bigscal-technology
      india
      1st Floor, B - Millenium Point,
      Opp. Gabani Kidney Hospital,
      Lal Darwaja Station Rd,
      Surat – 395003, Gujarat, INDIA.
      us
      1915, 447 Broadway,
      2nd Floor, New York,
      US, 10013
      +91 7862861254
      [email protected]

      • About
      • Career
      • Blog
      • Terms & Conditions
      • Privacy Policy
      • Sitemap
      • Contact Us
      Google reviews
      DMCA.com Protection Status
      GoodFirms Badge
      clutch-widget
      © Copyright - Bigscal - Software Development Company
      Google reviews
      DMCA.com Protection Status
      GoodFirms Badge
      clutch-widget

      Stay With Us

      Are you looking for the perfect partner for your next software project?

      Google reviews GoodFirms Badge clutch-widget
      • IP Rights, Security & NDA. Full ownership and confidentiality with robust security guaranteed.
      • Flexible Contracts & Transparency. Tailored contracts with clear and flexible processes.
      • Free Trial & Quick Setup. No-risk trial and swift onboarding process.

        The Ultimate Guide to New Features in F# 6 Uncover the Power of F# 6: Ultimate Guide guide to mastering Desktop Applications with Electron An Introduction to Building Desktop Applications with Electron
        Scroll to top

        We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

        AcceptHide notification onlySettings

        Cookie and Privacy Settings



        How we use cookies

        We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

        Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

        Essential Website Cookies

        These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

        Because these cookies are strictly necessary to deliver the website, refuseing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

        We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

        We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

        Other external services

        We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

        Google Webfont Settings:

        Google Map Settings:

        Google reCaptcha Settings:

        Vimeo and Youtube video embeds:

        Privacy Policy

        You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

        Privacy Policy
        Accept settingsHide notification only