react-google-map-picker icon indicating copy to clipboard operation
react-google-map-picker copied to clipboard

expected mapDiv of type Element but was passed null

Open saculdasilva opened this issue 4 years ago • 11 comments

On 1.2.2 sometimes the component returns "expected mapDiv of type Element but was passed null". Seems to be due to the 500ms timeout added on a quick glance. I managed to reproduce this passing only the style and api key parameters.

saculdasilva avatar Jan 04 '21 18:01 saculdasilva

Doesn't happen on 1.2.1, only on 1.2.2

saculdasilva avatar Jan 04 '21 18:01 saculdasilva

facing the same issue. Have you got any solution for it?

Shansabry avatar Feb 12 '21 03:02 Shansabry

facing the same issue. Have you got any solution for it?

I forced it to use version 1.2.1, meanwhile I started using tomchentw's react-google-maps instead. His Marker component has a draggable prop and onDragEnd returns coordinates, which is basically all I need on my use case.

lucas-sprwt avatar Feb 15 '21 16:02 lucas-sprwt

Ok Lucas, will take a look. will appreciate it if I get a working code block for it. If you don't mind, kindly share it

Shansabry avatar Feb 15 '21 16:02 Shansabry

Ok Lucas, will take a look. will appreciate it if I get a working code block for it. If you don't mind, kindly share it

Not the cleanest example but should give you a good starting point. Don't forget to add a key on the bottom for google maps.

import React, { Component } from "react"
import { withProps } from "recompose"
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps"

export class ExampleMap extends Component {

    constructor(props){
      super(props)
      this.state = {
        exampleCoords: { lat: 25.7617, lng: -80.1918 }
      }
    }

    render() {
        return (
            <>
                {/* The map itself, wraps map components */}
                <GoogleMap
                    options={{
                        mapTypeControl: false,
                        panControl: false,
                        streetViewControl: false,
                        zoomControl: true,
                    }}
                    defaultZoom={8}
                    center={this.state.exampleCoords}
                >
                        <Marker
                            position={this.state.exampleCoords}
                            draggable={true}
                            onDragEnd={(coords) => this.setState({ exampleCoords: {lat: coords.latLng.lat(), lng: coords.latLng.lng()} })}
                        />
                </GoogleMap>
            </>
        );
    }
}

export default withProps({
    googleMapURL: "https://maps.googleapis.com/maps/api/js?&key=" + "your_key_here" + "&v=3.exp&libraries=places",
    loadingElement: <div style={{ height: `400px` }} />,
    containerElement: <div style={{ height: `400px` }} />,
    mapElement: <div style={{ height: `400px` }} />
})(withScriptjs(withGoogleMap(ExampleMap)))

lucas-sprwt avatar Feb 15 '21 17:02 lucas-sprwt

Thank you so much Lucas

Shansabry avatar Feb 15 '21 17:02 Shansabry

I'm having the same problem however it works fine for me in 1 part of my application and not in another.

The difference being it works on where I show the map in a Modal Dialog, so it's not initially visible, perhaps this is something to do with the problem ?

The place where I just show it immediately on a page is failing as above.

chrisella avatar Sep 09 '21 11:09 chrisella

The solution for this error just use setTimeout function

`// ** React Imports import { Fragment, useState, useEffect } from 'react' import MapPicker from 'react-google-map-picker'

const MapPickerLocation = ({handleChangeLocation, location}) => {

const [show, setShow] = useState(false)

useEffect( () => { let timer = setTimeout(() => setShow(true), 1000);

  return () => {
    clearTimeout(timer);
  };
}, [])

if (!show) { return

Загрузка...
} return ( <Fragment> <MapPicker
defaultLocation={location} zoom={12} mapTypeId="roadmap" style={{height:'400px'}} onChangeLocation={handleChangeLocation} //onChangeZoom={handleChangeZoom} apiKey=''/> </Fragment> ) }

export default MapPickerLocation `

akhmadceo avatar Dec 25 '21 06:12 akhmadceo

@akhmadceo solution worked for me. Problem was the MapPicker would only load on a modal and give the error when not in a modal. On versions 1.2.2, 1.2.3 and 1.2.1.

iamkhaya avatar Jan 19 '22 22:01 iamkhaya

I read the code of this nice package and I found the issue. So when I have the time I will fix it and make a pull request

a-simplecode avatar Jun 23 '22 07:06 a-simplecode

@akhmadceo solution worked for me, thank you

abdulsamadayoade avatar Oct 10 '22 04:10 abdulsamadayoade