erdem / django-map-widgets

Highly customizable, intuitive, and user-friendly map widgets for GeoDjango applications.
MIT License
449 stars 119 forks source link

place.geometry can be undefined in handleAutoCompletePlaceChange #113

Closed fergusleahytab closed 4 years ago

fergusleahytab commented 4 years ago

Hi,

Found that place.geometry can sometimes be undefined. The google maps docs mention it could be because the user hit enter when no suggestion was present.

Here is the culprit. A simple check and return early would fix it.

handleAutoCompletePlaceChange: function (autocomplete) {
    var place = autocomplete.getPlace();
    var lat = place.geometry.location.lat();
    var lng = place.geometry.location.lng();
    this.updateLocationInput(lat, lng, place);
    this.fitBoundMarker()
},

from google's docs [1]:

var place = autocomplete.getPlace();
if (!place.geometry) {
    // User entered the name of a Place that was not suggested and
    // pressed the Enter key, or the Place Details request failed.
    ...

[1] https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete#try-it-yourself