Skip to content

Instantly share code, notes, and snippets.

@sungraiz
Last active October 16, 2019 14:47
Show Gist options
  • Select an option

  • Save sungraiz/a052215e939b1cfc542367b99a5afa22 to your computer and use it in GitHub Desktop.

Select an option

Save sungraiz/a052215e939b1cfc542367b99a5afa22 to your computer and use it in GitHub Desktop.
Now user can search by both coordinates and address.
if((/[a-z]/i.test(address))){
this.geocoder.geocode({'address': address}, function (results, status)
{
if ( status == window.google.maps.GeocoderStatus.OK )
{
that.updatePositionInput(results[0].geometry.location);
that.marker.setPosition(results[0].geometry.location);
that.map.setCenter(that.marker.position);
that.map.setZoom(15);
}
});
}else{
const latLngStr = address.split(',', 2),
newLatLang = new window.google.maps.LatLng( latLngStr[0], latLngStr[1] );
this.geocoder.geocode({ 'latLng': newLatLang }, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
that.updatePositionInput(newLatLang);
that.marker.setPosition(newLatLang);
that.map.setCenter(that.marker.position);
that.map.setZoom(15);
document.getElementById('address').value= results[0].formatted_address;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment