CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

[4.1][Feature][Needs testing] Google Maps field type (a.ka. lat_lng)

Open hedyharto opened this issue 7 years ago • 5 comments

Summary

Create an input form for location (latitude, longitude)

  • Maps
  • Search Autocomplete
  • Geolocation
  • Map click Event Listener
  • Require Google API key

Preview

latlng

Usage

$this->crud->addField([
    'name' => 'latlng',
    'label' => "Location",
    'type' => 'latlng',
    'google_api_key' => env('GOOGLE_API_KEY', null),
    'map_style' => 'height: 300px; width:auto',
    'default_zoom' => 17,
    'geolocate_icon' => 'fa-crosshairs',
    'marker_icon' => 'http://example.com/your-own-icon.png'
]);
  • google_api_key - get your own key
  • map_style - custom map style. The height attribute are required
  • default_zoom - map zoom
  • geolocate_icon - Font Awesome. p.s : this is not the right icon. Issue on Github
  • marker_icon - use null if you want to retain Google default marker icon

Known Issue

  1. Geolocation only work in "secure origins" (such as HTTPS) or on localhost
  2. Will not work if you are using tabs unless you put it in the first tab (loading problem)
  3. I have include the code below to overwrite CRUD submit on Enter
// overwrite BackPack-CRUD submit on Enter
$('#search_address').keydown(function(event){
    if(event.keyCode == 13) {
        event.preventDefault();
        return false;
    }
});

hedyharto avatar Mar 21 '17 02:03 hedyharto

This. Looks. AWESOME!!! Great job, @hedyharto . I'll give it a hard test tomorrow and include it in the next build.

Really nice work.

Cheers!

tabacitu avatar Apr 03 '17 17:04 tabacitu

Very very useful, But Any idea how to support mysql column of type POINT, instead of text column?

also would be great if there is a 'default_latlng' option for create blade

HusamAamer avatar Jul 12 '17 20:07 HusamAamer

@HusamAamer yes it would be nice if we have default field type for latlng e.g. 'type' => 'point', to reflect mysql's POINT column type.

hedyharto avatar Sep 02 '17 22:09 hedyharto

I with the commits were squashed 🙏

lloy0076 avatar Sep 03 '17 11:09 lloy0076

really nice

but i want to be able to get the search_address input value too appended to the lat lng value any idea how can i get the place name (location name) with the lat and lng values ?

odaiderawi avatar Apr 04 '19 15:04 odaiderawi

Closing this in favor of https://github.com/Laravel-Backpack/CRUD/pull/4110

Thanks for the contribution @hedyharto and sorry it didn't get merged, I've had dozens of my PR's closed too, it's just how it is sometimes. 🙃

Cheers

pxpm avatar Sep 12 '22 13:09 pxpm