Skip to content

Dooffy/google-map-react-polyline-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About

The project is an example how to render geodesic polyline on Google maps by using google-map-react package.

Polyline example screenshot

In the following code the onGoogleApiLoaded callback is using to get access to the loaded map and render a polyline on top of the map as showed on the image above.

  <GoogleMap
    // ...
    onGoogleApiLoaded={({map, maps}) => this.renderPolylines(map, maps)}>
    <!-- Markers here -->
  </GoogleMap>

  renderPolylines (map, maps) {
    let geodesicPolyline = new maps.Polyline({
      path: markers,
      // ...
    })
    geodesicPolyline.setMap(map)
  }

How to run the project on local environment

There are two examples of different methods how to render polyline on Google maps in the 'google-map-react-polyline-example/examples' folder

basic - use callback inside Map component

polyline-as-component - emulate React component behavior for polyline

To get the project on local environment clone project's repository and use one of the following commands

cd examples/basic
#or
cd examples/polyline-as-component

Update the line with valid google maps api key

bootstrapURLKeys={{key: 'PUT GOOGLE MAPS KEY HERE'}}

in the src/components/Map.js file.

Install required dependencies using yarn or npm and run project

yarn install
yarn start

To see the result of polyline rendering open http://localhost:3000/ in the browser

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published