Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

curved lines on google maps usint react

import React from "react";
import { GoogleMap, Polyline, useLoadScript } from '@react-google-maps/api'
const containerStyle = {
  width: '100%', //or any other form of width px, em, rem,
  height: '300px',
  margin: '1rem',
  zindex: 1,
};
// must include geometry for curved lines
const libraryList = ['places', 'geometry']
const center = {lat: 0, lng: 0}
const api_Key = "your google api key"
// your gps points to connect in sequence can be from props etc
const path = [
  {lat: -19.079030990601, lng: -169.92559814453}, //first/start
  {lat: 28.2014833, lng: -177.3813083},
  {lat: 39.849312, lng: -104.673828},
  {lat: 16.7249971, lng: -3.00449998}  // last/finish
];
//geodesic: true for curve, otherwise straight lines
const pathOptions = {
  strokeColor: '#FF0000',
  strokeOpacity: 0.5,
  strokeWeight: 2,
  fillColor: '#FF0000',
  fillOpacity: 0.5,
  clickable: false,
  draggable: false,
  editable: false,
  visible: true,
  radius: 30000,
  paths: path,
  geodesic: true,
  zIndex: 2
};

function Map() {
  const {isLoaded, loadError} = useLoadScript({
    googleMapsApiKey: api_Key,
    libraryList,
  })
  if (loadError) return "Error msg or function"
  if (!isLoaded) return "Loading msg or function"
  return (
    <div>
      <h2>A nice map title</h2>
      <GoogleMap 
      	mapContainerStyle={containerStyle} 
      	zoom={2} 
      	center={center}
      	mapTypeId={'satellite'} //can be omitted
      >
        <Polyline 
			path={path} 
			options={pathOptions} 
		/>
      </GoogleMap>
    </div>
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: simultaneos mouse buttons clicked js 
Javascript :: nextjks using window or document object 
Javascript :: crear etiquetas html con javascript 
Javascript :: webpack test js or jsx 
Javascript :: how to use aos 
Javascript :: calculate sum in empty array javascript 
Javascript :: set to array casting js 
Javascript :: get input string js 
Javascript :: how to add debounce in react redux js 
Javascript :: fetch is not defined jest react 
Javascript :: how to add multiple style attributes in react element 
Javascript :: javascript add to undefined 
Javascript :: Flutter list of JSONs to Objects 
Javascript :: node_modules/react-native-paper/lib/module/core/Provider.js 
Javascript :: js string to charcode array 
Javascript :: how to use react memo hooks 
Javascript :: how to assert input value in testing library 
Javascript :: coderbyte find intersection solutions 
Javascript :: node.js process.argv 
Javascript :: if else react render in jsc 
Javascript :: start nodemon under wsl2 
Javascript :: json schema e.g. 
Javascript :: sort array of objects based on another array javascript 
Javascript :: get image from s3 bucket angular 
Javascript :: vue js data bind 
Javascript :: check if an array is empty 
Javascript :: React Redux reducer crud 
Javascript :: javascript compress base64 image 
Javascript :: change dictionary value in React js 
Javascript :: includes in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =