question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not pan map after select geosearch result

See original GitHub issue

I use leaflet-geosearch 3.0.5. I do not use leaflet-geosearch own marker as I want to use my own draggable marker.

Before select search result, I can pan map or drag my own marker. When user select search result, I set my draggable marker position based on selected address location and map is centered to marker. It works fine.

The problem is after that I can not pan map when I drag outside marker. I can only drag marker. This is my code.

<script src='https://api.mapbox.com/mapbox.js/v3.3.1/mapbox.js'></script>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'></script>
<script src="https://unpkg.com/leaflet-geosearch@3.0.5/dist/geosearch.umd.js"></script>

<script>
$(document).ready(function(){
    var centerView = [{{ config('map.mapbox.center.latitude') }}, {{ config('map.mapbox.center.longitude') }}];

    L.mapbox.accessToken = '{{ config('map.mapbox.key') }}';

    var map = L.mapbox.map('map')
        .setView(centerView, {{ config('map.mapbox.zoom') }})
        .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'))
        .addControl(new L.Control.Fullscreen())
        .addControl(
            new GeoSearch.GeoSearchControl({
                showMarker : false,
                autoClose : true,
                searchLabel : 'Search address',
                notFoundMessage : 'Address is not found',
                provider: new GeoSearch.OpenStreetMapProvider()
            })
        );

    var marker = L.marker(centerView, {
        draggable: true
    }).addTo(map);

    //handle geocoder event when location is found
    map.on('geosearch/showlocation', function(e) {
        var newLatLng = new L.LatLng(e.location.y, e.location.x);
        marker.setLatLng(newLatLng);
        $('#latitude').val(newLatLng.lat);
        $('#longitude').val(newLatLng.lng);
    });

    var ondragend = function () {
        var ll = marker.getLatLng();
        $('#latitude').val(ll.lat);
        $('#longitude').val(ll.lng);
    };

    // every time the marker is dragged, update the form
    marker.on('dragend', ondragend);

    // set the initial values in the form
    ondragend();

});
</script>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zamronypjcommented, Jul 6, 2021

@smeijer I can confirm, upgrading to 3.3.2 fix issue.

0reactions
smeijercommented, Jul 7, 2021

Thanks for reporting back @zamronyp

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting coordinates after address has been picked in ...
I need to retrieve the result once the user has picked the correct address from the search bar, so I can make spatial...
Read more >
smeijer/leaflet-geosearch: A geocoding/address-lookup ...
Default behaviour is to zoom and pan to the search result. With retainZoomLevel on true , the map is only panned. animateZoom controls...
Read more >
L.GeoSearch
Before select search result, I can pan map or drag my own marker. When user select search result, I set my draggable marker...
Read more >
Leaflet geosearch - binding results marker to an existing one
I took a quick peek into their source code and that property is only used to extract its values, it won't actually use...
Read more >
geoSearch | InstantSearch.js
An InstantSearch.js widget for showing search results on a Google Map based on ... .ais-GeoSearch-map { height: 500px; /* You can change this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found