Unable to get google's map object
See original GitHub issueHere is my component:
'use strict';
import React from 'react';
import {withGoogleMap, GoogleMap} from 'react-google-maps';
import {MAP} from 'react-google-maps/lib/constants';
export default class Presentation extends React.Component {
static contextTypes = {
[MAP]: React.PropTypes.object
}
render() {
var _this = this;
const MyMap = withGoogleMap((props) => (
<GoogleMap
defaultCenter: {
lat: 38.809972,
lng: -100.60729
},
defaultZoom: 5,
onDragEnd={(e) => {
console.log(_this.context[MAP]);
console.log(e.latLng.lat(), e.latLng.lng());
}}
></GoogleMap>
));
return (
<MyMap
loadingElement={<div className="map-loading" />}
containerElement={<div className="map-container" />}
mapElement={<div className="map-element" />}
/>
);
}
}
In onDragEnd function I want to get google’s map object.
Here I found an example how to do that: https://github.com/tomchentw/react-google-maps/issues/161
(I mean using context)
But _this.context[MAP]
is always undefined for me.
Please provide any workable example or just tell me what is wrong with mine.
- “react”: “^15.4.0”
- “react-google-maps”: “^9.4.5”
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Error Messages | Maps JavaScript API - Google Developers
You may have supplied an incorrect version number in your script element. Please make sure you are using a correct version number. See...
Read more >Get google.maps.Map instance from a HTMLElement
You can't get google.maps.Map object from DOM Element ,on which Google Maps object have been constructed. google.maps.Map is just a wrapper, ...
Read more >@react-google-maps/api - npm
If you want to use window.google object, you need to extract GoogleMap in separate module, so it is lazy executed then google-maps-api script...
Read more >Google Maps not working on your iPhone? 12 Real fixes
You might also find this fix helpful if Google Maps fails to launch or ... Google Maps accuracy as it lets you scan...
Read more >How to fix Maps when it crashes - Android - Google Maps Help
Clear the app's cache & data · On your Android phone or tablet, open the Settings app . · Tap Apps & notifications....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, this works for me too, big thanks!!)
I’ve been trying to figure out how to update the current center coords, this is what worked for me.