Recognized by Clutch.co as a top-rated Mobile App Development Company.
folio3-mobile
US 408 365 4638
START YOUR PROJECT
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise
    • AR/VR
    • IoT
    • Wearables
    • Field Sales
    • On Demand Apps
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical & Life Sciences
    • Manufacturing
    • Automotive
    • Logistics
    • Education
  • Technologies
    • Native Mobile Apps
      • iOS
      • Android
    • Cross Platform Apps
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • Sencha
  • Portfolio
  • Blog
  • Contact Us
Menu
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise
    • AR/VR
    • IoT
    • Wearables
    • Field Sales
    • On Demand Apps
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical & Life Sciences
    • Manufacturing
    • Automotive
    • Logistics
    • Education
  • Technologies
    • Native Mobile Apps
      • iOS
      • Android
    • Cross Platform Apps
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • Sencha
  • Portfolio
  • Blog
  • Contact Us

What is Google Maps Geometry Library & How it Works?

Published by: Muhammad Saqlain | September 23, 2021 msaqlain
SCROLL AND BE AMAZED!
Home > Blog > What is Google Maps Geometry Library & How it Works?

The earth is round, the map is flat

When calculating the distance between two latitudes and longitudes we need to take the fact that maps are flat, however, the Earth is three-dimensional (round) and is approximated as a sphere.

Map

The black line is the shortest path possible but when plotting on flat map it will look like an arc (the red line). Therefore calculating distance between two coordinates needs to use very advanced mathematics.

Fortunately, with Google Maps API 3 libraries, Google Map offers a Geometry library which makes it very simple to calculate distance.

Google Maps geometry library provides functions for the computation of geometric data on the surface of the earth. All it requires is to call the computeDistanceBetween() function passing it two LatLng objects.

Loading the Maps JavaScript API

http://maps.google.com/maps/api/js?libraries=geometry&sensor=true&key=YOUR_API_KEY

Geometry Library Namespaces

  • google.maps.geometry.spherical

Contains spherical geometry utilities allowing you to compute angles, distances & areas from coordinates (latitudes and longitudes).

  • google.maps.geometry.encoding

Contains utilities for encoding and decoding paths for polylines and polygons. Useful to compress bulky list of coordintes.

Calculating Distance

var location1 = new google.maps.LatLng(38.715, -74.002);
var location2 = new google.maps.LatLng(41.506, -0.119);
var distance = google.maps.geometry.spherical.computeDistanceBetween(location1, location2);

Results are returned in meters.

Computing Heading

var location1 = new google.maps.LatLng(38.715, -74.002);
var location2 = new google.maps.LatLng(41.506, -0.119);
const heading = google.maps.geometry.spherical.computeHeading(
    location1,
    location2
  );

Results are returned in degrees from the north.

Calculating Area

var location1 = new google.maps.LatLng(38.715, -74.002);
var location2 = new google.maps.LatLng(41.506, -0.119);
var location3 = new google.maps.LatLng(20.916, -43.251);
var area = google.maps.geometry.spherical.computeArea([location1, location2, location3]);

Code above will calculate the area of a triangle between three locations provided to computeArea()

Conclusion

Calculating area, heading and distances on geo coordinates can be tricky and may require advanced mathematics, but with the help of the Google Maps Geometry Library it’s really simple. Thanks for reading.


About msaqlain

A hardworking and dedicated individual, determined on the road to success, ever ready to take on challenges and accomplish what I set out to achieve.

Newsletter

Search

Archives

  • April 2022
  • March 2022
  • February 2022
  • October 2021
  • September 2021
  • May 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • May 2019
  • Categories

    • Android App Development
    • App Development
    • App Testing
    • Blog
    • Elasticsearch
    • flutter-app-development
    • IOT
    • React Native
    • Staff Augmentation

Recent Posts

  • Introduction to Nessus Vulnerability Scanning Tool
  • Error Boundary in React Native
  • Speech to Text Recognition in React Native
  • How to Patch NPM Packages
  • Firebase Crashlytics Integration in React Native

Tags

  • android
  • Automation
  • cross-platform
  • development
  • firebase
  • ios
  • QA
  • react-native
  • Testing
  • Test Script

Newsletter

Newsletter

Post navigation

Previous Handling Background Location Permissions in React Native
Next Automate React Native App Builds With Fastlane And Appcenter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Schedule an appointment with our Mobile App Development Expert

    Footer Menu
    • Company
      • About Us
      • Portfolio
      • Blog
      • Careers
      • Contact Us
    • Solutions
      • Apps Discovery Services
      • Team Augmentation
      • Enterprise App Development
      • AR/VR Application Development
      • IoT Application Development
      • Wearables Apps Development
      • Field Sales
      • On-Demand Apps Development
    • Technologies
      • iOS
      • Android
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • HTML5
      • Sencha
    • Industries
      • Retail
      • Agriculture
      • Healthcare
      • Pharmaceutical
      • Manufacturing
      • Automotive
      • Logistics
      • Education

    US Office

    Belmont, California – 1301 Shoreway Road, Suite 160, Belmont, CA 94002

    Pleasanton, California – 6701 Koll Center Parkway, #250 Pleasanton, CA 94566

    Tel: +1 408 365 4638
    Support: +1 (408) 512 1812

    Mexico Office

    Amado Nervo #2200, Edificio Esfera 1 piso 4, Col. Jardines del Sol, CP. 45050, Zapopan, Jalisco, Mexico

    Bulgaria Office

    49 Bacho Kiro Street, Sofia, 1000, Bulgaria

    Canada Office​

    895 Don Mills Road, Two Morneau Shepell Centre, Suite 900, Toronto, Ontario, M3C 1W3, Canada

    UK Office

    Export House, Cawsey Way, Woking Surrey, GU21 6QX

    Tel: +44 (0) 14 8361 6611

    UAE Office

    Dubai, UAE – Dubai Internet City, 1st Floor, Building Number 12, Premises ED 29, Dubai, UAE

    Tel: +971-55-6540154
    Tel: +971-04-2505173

    Pakistan Office

    163 Bangalore Town, Main Shahrah-e-Faisal, Karachi –
    75350

    705, Business Center, PECHS Block-6, Shahrah-e-Faisal,
    Karachi – 75350

    First Floor, Blue Mall 8-R, MM Alam Road Gulberg III, Lahore

    Tel: +92-21-3432 3721-4 

    © 2021, Folio3 Software Inc., All rights reserved.

    • Privacy policy and terms of use
    • Cookie Policy
    Follow us on
    Facebook-f
    Twitter
    Linkedin-in

    Get a free app audit

      Tired of your app not performing up to the mark?

      Get a free technology and app strategy review.