Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import React from 'react';
  2. import { GoogleMap, LoadScriptNext, Marker } from '@react-google-maps/api';
  3.  
  4. const GoogleMaps = ({
  5. apiKey,
  6. containerClass,
  7. defaultZoom,
  8. isMarkerDraggable,
  9. latitude,
  10. longitude,
  11. mapCenter,
  12. setCoordinates,
  13. }) => {
  14. const hasCoordinates = !!latitude && !!longitude;
  15.  
  16. const handleEndDragMarker = (e) => {
  17. if (!e.latLng) { return; }
  18.  
  19. const { lat, lng } = e.latLng;
  20.  
  21. setCoordinates({
  22. latitude: lat(),
  23. longitude: lng(),
  24. });
  25. };
  26.  
  27. return (
  28. <LoadScriptNext
  29. id="script-loader"
  30. googleMapsApiKey={apiKey}
  31. >
  32. <GoogleMap
  33. center={ mapCenter }
  34. id='example-map'
  35. mapContainerClassName={containerClass}
  36. zoom={ defaultZoom }
  37. options= {
  38. {
  39. streetViewControl: false,
  40. controlSize: 24,
  41. }
  42. }
  43. >
  44. {
  45. hasCoordinates &&
  46. <Marker
  47. draggable={ isMarkerDraggable }
  48. onDragEnd={ handleEndDragMarker }
  49. position={{ lat: latitude, lng: longitude }}
  50. />
  51. }
  52. </GoogleMap>
  53. </LoadScriptNext >
  54. )
  55. }
  56.  
  57. export default GoogleMaps;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement