Hello everybody. The repo of this project is unmaintained more than 3 years, and we had build new version https://www.npmjs.com/package/@react-google-maps/api
We had rewrite it to TypeScript, and updating it frequently: https://github.com/JustFly1984/react-google-maps-api/tree/master/packages/react-google-maps-api
You can enjoy autocomplete.
You can see our docs: https://react-google-maps-api-docs.netlify.app
Also a lot of examples: https://react-google-maps-api-gatsby-demo.netlify.app/ https://github.com/JustFly1984/react-google-maps-api/tree/master/packages/react-google-maps-api-gatsby-example/src/examples
The bundle size is much smaller: https://bundlephobia.com/result?p=@react-google-maps/api
Our Spectrum community: https://spectrum.chat/react-google-maps Our Slack channel: https://join.slack.com/t/react-google-maps-api/shared_invite/enQtODc5ODU1NTY5MzQ4LTBiNTYzZmY1YmVjYzJhZThkMGU0YzUwZjJkNGJmYjk4YjQyYjZhMDk2YThlZGEzNDc0M2RhNjBmMWE4ZTJiMjQ
Enjoy!
How do i make a basic React Application which has the following:
2 input fields:
Both of the above fields should have Google Maps search API integrated into them so that we are able to search for a particular location (with auto-complete)
Below these inputs there will be a Map displayed which will show us markers at the Source, Destination and the Route between the two locations.
https://maps.googleapis.com/maps/api/js?key=${siteSettings.googleMaps.apiKey}&map_ids=${siteSettings.googleMaps.mapID}&callback=initMap
hello. so i am not new to react or js but i am trying to implement this API for the first time in a project and i woud like to do some forecasting.
I am interested in the server requirements for this API to work effectively eg: will it work on shared hosting or does it require vps. Will it need some special features like cron jobs? ... etc.
I am also interested in knowing whether it will need server-side integration of some sort or it only works on the client.
Are there any differences in the integration for this and the integration for google maps.
import React, { PureComponent } from "react";
import {
withGoogleMap,
GoogleMap,
DirectionsRenderer,
withScriptjs,
} from "react-google-maps";
class Map extends PureComponent {
constructor(props) {
super(props);
this.state = {
directions: null,
cords: null,
userFrom: parseFloat(this.props.routing.latitude_from),
userto: parseFloat(this.props.routing.longitude_from),
destinationFrom: parseFloat(this.props.routing.latitude_to),
destinationto: parseFloat(this.props.routing.longitude_to),
};
}
componentDidMount() {
const { userFrom, userto, destinationFrom, destinationto } = this.state;
const directionsService = new window.google.maps.DirectionsService();
const directionsRenderer = new window.google.maps.DirectionsRenderer();
const origin = { lat: userFrom, lng: userto };
const destination = {
lat: destinationFrom,
lng: destinationto,
};
directionsService.route(
{
origin: origin,
destination: destination,
travelMode: window.google.maps.TravelMode.DRIVING,
},
(result, status) => {
directionsRenderer.setDirections({ result });
var route = result.routes[0].legs[0];
const coords = result.routes[0].overview_path;
if (status === window.google.maps.DirectionsStatus.OK) {
this.setState({
directions: result,
distance: route.distance.text,
duration: route.duration.text,
cords: coords,
});
} else {
console.error(error fetching directions ${result}
);
}
}
);
}
render() {
const GoogleMapExample = withGoogleMap((props) => (
<GoogleMap
defaultCenter={{ lat: this.state.userFrom, lng: this.state.userto }}
defaultZoom={10}
>
<DirectionsRenderer
directions={this.state.directions}
onDirectionsChanged={(e) => console.log(e)}
options={{
polylineOptions: {
strokeColor: "#1171ef",
strokeOpacity: 1,
strokeWeight: 4,
},
}}
/>
</GoogleMap>
));
return (
<div>
<GoogleMapExample
containerElement={<div style={{ height: `350px`, width: "100%" }} />}
mapElement={<div style={{ height: `100%` }} />}
></GoogleMapExample>
</div>
);
}
}
const MapLoader = withScriptjs(Map);
export default MapLoader;
{type: "circle", overlay: _.fj}overlay: _.fj {gm_accessors_: {…}, fillColor: "#ffff00", gm_bindings_: {…}, fillOpacity: 1, strokeWeight: 5, …}type: "circle"[[Prototype]]: Object
PolyMap.js?867b:171 _.fj {gm_accessors_: {…}, fillColor: "#ffff00", gm_bindings_: {…}, fillOpacity: 1, strokeWeight: 5, …}Ne: $i {gm_bindings_: {…}, __gm: Aca, gm_accessors_: {…}, renderingType: "RASTER", mapTypeId: "hybrid", …}Vq: (3) [Wf, Wf, Wf]Xe: _.VB {i: div, g: _.WA, j: _.SA, gm_bindings_: {…}, gm_accessors_: {…}, …}center: _.zf {lat: ƒ, lng: ƒ}clickable: falseclosure_uid_543128641: 461draggable_changed: ƒ c()editable: trueeditable_changed: ƒ e()eq: SH {i: _.hj, gm_bindings_: {…}, g: Array(10), __e3_: {…}, ob: _.Hi, …}fillColor: "#ffff00"fillOpacity: 1gm_accessors_: {fillColor: null, fillOpacity: null, strokeWeight: null, clickable: null, editable: null, …}gm_bindings_: {fillColor: {…}, fillOpacity: {…}, strokeWeight: {…}, clickable: {…}, editable: {…}, …}listeners: (11) [Wf, Wf, Wf, Wf, Wf, Wf, Wf, Wf, Wf, Wf, Wf]map: $i {gm_bindings_: {…}, __gm: Aca, gm_accessors_: {…}, renderingType: "RASTER", mapTypeId: "hybrid", …}nr: OH {gm_bindings_: {…}, g: _.SA, gm_accessors_: {…}}radius: 246.17354060977704strokeWeight: 5ti: _.ZB {g: _.kr, gm_accessors_: {…}, strokeColor: "#000000", gm_bindings_: {…}, strokeOpacity: 1, …}un: MH {H: OH, o: KH, i: false, g: _.di, N: ƒ, …}visible: truezIndex: 1__e3_: {toolbar: {…}, mouseover: {…}, click: {…}, mouseout: {…}}[[Prototype]]: _.J
PolyMap.js?867b:171