Giter VIP home page Giter VIP logo

leaflet-geosearch's Introduction

Leaflet.GeoSearch

All Contributors

Demo and Docs: smeijer.github.io/leaflet-geosearch

animation of geosearch

Installation

more docs @ https://smeijer.github.io/leaflet-geosearch/#installation

with npm:

npm install --save leaflet-geosearch

or yarn:

yarn add leaflet-geosearch

Browser support / Polyfills

more docs @ https://smeijer.github.io/leaflet-geosearch/#browser-support--polyfills

This library is written with the latest technologies in mind. Thereby it is required to include some polyfills when you wish to support older browsers. These polyfills are recommended for IE and Safari support:

About

This library adds support for geocoding (address lookup, a.k.a. geoseaching) to your (web) application. It comes with controls to be embedded in your Leaflet map.

Check out the docs for various possibilities.

The library uses so-called "providers" to take care of building the correct service URL and parsing the retrieved data into a uniform format. Thanks to this architecture, it is pretty easy to add your own providers, so you can use your own geocoding service(s).

The control comes with a number of default providers:

Although this project is still named leaflet-geosearch, this library is also usable without LeafletJS, and does not have any dependencies whatsoever.

Usage

more docs @ https://smeijer.github.io/leaflet-geosearch/usage

Let's first start with an little example on how to use this control without leaflet. For example as an address lookup on a webshop order form. Perhaps to search for the closest alternative package delivery point? Or to link it to your own custom map component.

// import
import { OpenStreetMapProvider } from 'leaflet-geosearch';

// setup
const provider = new OpenStreetMapProvider();

// search
const results = await provider.search({ query: input.value });

Of course, something like this should be bound to something like a form or input:

import { OpenStreetMapProvider } from 'leaflet-geosearch';

const form = document.querySelector('form');
const input = form.querySelector('input[type="text"]');

form.addEventListener('submit', async (event) => {
  event.preventDefault();

  const results = await provider.search({ query: input.value });
  console.log(results); // » [{}, {}, {}, ...]
});

Instead of es6 async / await you can also use promises like:

provider.search({ query: '...' }).then(function (result) {
  // do something with result;
});

Results

The search event of all providers return an array of result objects. The base structure is uniform between the providers. It provides a object like:

const result = {
  x: Number, // lon,
  y: Number, // lat,
  label: String, // formatted address
  bounds: [
    [Number, Number], // s, w - lat, lon
    [Number, Number], // n, e - lat, lon
  ],
  raw: {}, // raw provider result
};

The contents of the raw property differ per provider. This is the unprocessed result from the 3th party service. This property is included for developer convenience. leaflet-geosearch does not use it. If you need to know the contents of this property, you should check the 3th party developer docs. (or use your debugger)

Providers

When OpenStreetMap does not match your needs; you can also choose to use the Algolia, Bing, Esri, Geocode Earth, Google, LocationIQ, OpenCage, or Pelias providers. Most of those providers do however require API keys. See the documentation pages on the relevant organisations on how to obtain these keys.

In case you decide to write your own provider, please consider submitting a PR to share your work with us.

Providers are unaware of any options you can give them. They are simple proxies to their endpoints. There is only one special property, and that is the params option. The difference being; that params will be included in the endpoint url. Often being used for API KEYS, where as the other attributes can be used for provider configuration.

Using with LeafletJS

This project comes with a leaflet control to hook the search providers into leaflet. The example below uses the OpenStreetMap Provider, but you can exchange this with on of the other included providers as well as your own custom made providers. Remember to setup the provider with a key when required (Google and Bing for example).

search control

import L from 'leaflet';
import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';

const provider = new OpenStreetMapProvider();

const searchControl = new GeoSearchControl({
  provider: provider,
});

const map = new L.Map('map');
map.addControl(searchControl);

Using with react-leaflet

Usage with react-leaflet is similar to the usage with plain Leaflet. This example uses the new MapBoxProvider and adds an api key to the params list when accessing the remote API. Note the useMap hook which is the only notable diffrence to the leaflet example.

import { GeoSearchControl, MapBoxProvider } from 'leaflet-geosearch';
import { useMap } from 'react-leaflet';
const SearchField = ({ apiKey }) => {
  const provider = new MapBoxProvider({
    params: {
      access_token: apiKey,
    },
  });

  // @ts-ignore
  const searchControl = new GeoSearchControl({
    provider: provider,
  });

  const map = useMap();
  useEffect(() => {
    map.addControl(searchControl);
    return () => map.removeControl(searchControl);
  }, []);

  return null;
};

The useEffect hook used in SearchField even allows for conditional rendering of the search field.

import { MapContainer } from 'react-leaflet';
const MyMap = () => {
  // ...
  return (
    <MapContainer>
      {showSearch && <SearchField apiKey={apiKey} />}

      {/* ... */}
    </MapContainer>
  );
};

GeoSearchControl

There are some configurable options like setting the position of the search input and whether or not a marker should be displayed at the position of the search result.

search button There are two visual styles of this control. One is the more 'leaflet-way' by putting the search control under a button (see image above). And one where the search control is permanently shown as a search bar (see image under using with LeafletJS).

Render style

This render style can be set by the optional style option.

new GeoSearchControl({
  provider: myProvider, // required
  style: 'bar', // optional: bar|button  - default button
}).addTo(map);

AutoComplete

Auto complete can be configured by the parameters autoComplete and autoCompleteDelay. A little delay is required to not DDOS the server on every keystroke.

new GeoSearchControl({
  provider: myProvider, // required
  autoComplete: true, // optional: true|false  - default true
  autoCompleteDelay: 250, // optional: number      - default 250
}).addTo(map);

Show result

There are a number of options to adjust the way results are visualized.

new GeoSearchControl({
  provider: myProvider, // required
  showMarker: true, // optional: true|false  - default true
  showPopup: false, // optional: true|false  - default false
  marker: {
    // optional: L.Marker    - default L.Icon.Default
    icon: new L.Icon.Default(),
    draggable: false,
  },
  popupFormat: ({ query, result }) => result.label, // optional: function    - default returns result label,
  resultFormat: ({ result }) => result.label, // optional: function    - default returns result label
  maxMarkers: 1, // optional: number      - default 1
  retainZoomLevel: false, // optional: true|false  - default false
  animateZoom: true, // optional: true|false  - default true
  autoClose: false, // optional: true|false  - default false
  searchLabel: 'Enter address', // optional: string      - default 'Enter address'
  keepResult: false, // optional: true|false  - default false
  updateMap: true, // optional: true|false  - default true
});

showMarker and showPopup determine whether or not to show a marker and/or open a popup with the location text.

marker can be set to any instance of a (custom) L.Icon.

popupFormat is callback function for displaying text on popup.

resultFormat is callback function for modifying the search result texts (e. g. in order to hide address components or change its ordering).

maxMarker determines how many last results are kept in memory. Default 1, but perhaps you want to show the last x results when searching for new queries as well.

retainZoomLevel is a setting that fixes the zoomlevel. Default behaviour is to zoom and pan to the search result. With retainZoomLevel on true, the map is only panned.

animateZoom controls whether or not the pan/zoom moment is being animated.

autoClose closes the result list if a result is selected by click/enter.

keepResult is used to keep the selected result in the search field. This prevents markers to disappear while using the autoClose feature.

updateMap controls whether or not the map re-centers on the selection.

Events

geosearch/showlocation is fired when location is chosen from the result list.

map.on('geosearch/showlocation', yourEventHandler);

geosearch/marker/dragend is fired when marker has been dragged.

map.on('geosearch/marker/dragend', yourEventHandler);

Development

Checkout the providers to see how easy it is to write your own. For research it can be interesting to see the difference between Bing and the others; because Bing does not support CORS, and requires jsonp to be used instead.

In case you decide to write your own provider, please consider submitting a PR to share your work with us.

You can use the docs as "development environment". Please run npm run start to get up and running. The docs will refresh when you change source files.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Stephan Meijer
Stephan Meijer

🤔 💻 🚇 🚧 ⚠️
Yurii Zinets
Yurii Zinets

💻 ⚠️ 🤔
David Hubner
David Hubner

💻
Nikolay Ninarski
Nikolay Ninarski

💻
Fredrik Ekelund
Fredrik Ekelund

💻
Rémi Duraffort
Rémi Duraffort

💻
Bung
Bung

💻
Cajus Pollmeier
Cajus Pollmeier

💻
Dan Dascalescu
Dan Dascalescu

💻
Devdatta Tengshe
Devdatta Tengshe

💻
emiltem
emiltem

💻
Johannes Raggam
Johannes Raggam

💻
Nathan Cahill
Nathan Cahill

💻
Tim Wisniewski
Tim Wisniewski

💻
Alex Balhatchet
Alex Balhatchet

💻 ⚠️ 🤔
Andreas Heigl
Andreas Heigl

💻
Arthur Toussaint
Arthur Toussaint

💻
Austin Brown
Austin Brown

💻
Brian Herbert
Brian Herbert

💻
Chris McDonald
Chris McDonald

💻
David Kobia
David Kobia

💻
 Dmytro Borysovskyi
Dmytro Borysovskyi

💻
Francis Lavoie
Francis Lavoie

💻
Ivan Gromov
Ivan Gromov

💻
Jason Pettett
Jason Pettett

💻
Johan
Johan

💻
Matt Krueger
Matt Krueger

💻
Mithgol
Mithgol

💻
mosh11
mosh11

💻
Sajjad Anwar
Sajjad Anwar

💻
Steve
Steve

💻
Stuart P. Bentley
Stuart P. Bentley

💻
joshrainwater
joshrainwater

💻
maxlath
maxlath

💻
Dariusz Pawlak
Dariusz Pawlak

💻
Ivelin Ralev
Ivelin Ralev

💻 ⚠️ 🤔
Srihari Thalla
Srihari Thalla

💻 ⚠️ 🤔
Kate Lizogubova
Kate Lizogubova

💻
Cory Leigh Rahman
Cory Leigh Rahman

🤔 💻
Oliver Jägle
Oliver Jägle

💻
Kyle Houghton
Kyle Houghton

💻
nikitauskas
nikitauskas

💻
Patrice De Saint Steban
Patrice De Saint Steban

💻 📖
AntoineAA
AntoineAA

💻
HolyMarcell
HolyMarcell

📖
Grigor Pavlov
Grigor Pavlov

💻
Peter Johnson
Peter Johnson

💻 ⚠️
Arnaud Ferrand
Arnaud Ferrand

📖
Konstantinos Stratis
Konstantinos Stratis

💻 ⚠️ 📖
Darren
Darren

💻 ⚠️ 📖
Paul Schreiber
Paul Schreiber

💻
Nick Silvestri
Nick Silvestri

🤔 💻
teriblus
teriblus

💻
Tim Hirzel
Tim Hirzel

💻
David Barina
David Barina

💻
mugu-fatman
mugu-fatman

💻
Zach Stednick
Zach Stednick

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

leaflet-geosearch's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leaflet-geosearch's Issues

won't work inside bootstrap

I can't figure out why I'm getting a "400 bad request error". I'm sure It’s something simple but beyond me. In Firebug the parameters are incomplete. Any chance you could take a look if it's not too much trouble. I've been working on it for a few days and I haven’t a clue what's wrong.

http://capecodgis.com/map-demos.html

Returns incorrect map property in '_getZoomLevel' function.

  • When retainZoomLevel property is set to true, _getZoomLevel function returns zoom property from map. Whereas there is no such property as zoom under map and hence undefined is returned. When _zoom is returned from _getZoomLevel it is working fine. (Raising a PR)
  • Refer the Leaflet source code (getZoom function).

Set default city.

Set default city for quick search. People are lazy enough to not type in the complete address. This will help improve the results and also limit the search to that particular region.

Thoughts?

Restrict results to a country

I have been trying to restrict the results of a search to the UK using the Google API and changing the URL to include an address and component filtering, however this doesn't appear to work, is there a better way of doing this?

marker lat long

How would I capture the lat long of the geosearch result?

How to change custom marker position.

new L.Control.GeoSearch({
                        provider: new L.GeoSearch.Provider.Google(),
                        showMarker: false
                    }).addTo(map);
map.on('geosearch_showlocation', function (data) {
                        var lat = data.Location.Y, lng = data.Location.X;
                        leafMarker.setLatLng(new L.LatLng(lat, lng));
                    });

For those who want their marker, not some generic one :)

German umlauts may not work due to encoding issues with OSM

We use parts of the geosearch code for placing a marker on a leaflet map. If you use a browser on some windows systems and input a address containing umlauts like "ä" or "ü" then you will get a 400 response from OSM. This can be fixed by encoding the query before passing it to L.Util.getParamString().

We have done this at https://github.com/smeijer/L.GeoSearch/blob/master/src/js/l.geosearch.provider.openstreetmap.js#L22-23

The commit in our project was: eXma/meet-and-eat-registration-system@2067b0a

How to call the search function in a dropdown menu bar?

Hello,

i have the following problem:
my target is a hybrid app with leaflet. I create a dropdown menu with html/CSS/JQuery.
Here is the code:

<nav>
<ul>
    <li id="menuPoint1"><image src="../img/Icon/info.png"/>
        <ul class="subMenuPoint1">
            <li class="firstLi"><a href='#'>Interpretation</a></li>
            <li ><a href='#'>Kennblatt</a></li>
            <hr>
            <image src="http://maps.ioer.de/cgi-bin/wms?MAP=S02RG_1000&&SERVICE=WMS&VERSION=1.3.0&SLD_VERSION=1.1.0&REQUEST=GetLegendGraphic&FORMAT=image/jpeg&LAYER=S02RG_2012_a"/>
        </ul>
    </li>
    <li id="menuPoint2"><image src="../img/Icon/ebenen.png"/></li>
    <li id="menuPoint3"><image src="../img/Icon/kalender.png"/></li>
    <li id="menuPoint4"><image src="../img/Icon/lupe.png"/>
        <ul class="subMenuPoint4">
            <li id="search"></li>
        </ul>
    </li>
    <li id="menuPoint5"><image src="../img/Icon/helligkeit.png"/></li>
</ul>

Now I like to call the search function at the point li id="search".

I know how to call the function within the javascript part, but not within the list element, which is outside the Leaflet function.

My code for the Leaflet Map is:

new L.Control.GeoSearch({
        position: 'topcenter',
        provider: new L.GeoSearch.Provider.OpenStreetMap(),
    }).addTo(map);

which I like to implement in the dropdown menu.

Much thanks for Help !

position: 'topcenter' from the example doesn't work

It seems that in the current version when calling new L.Control.GeoSearch the argument position: 'topcenter' doesn't seem to work (javascript error). This is unfortunate because I think the topcenter position (which I saw working in an earlier version) was the nicest positioning option.

Mention jQuery requirement

There's no mention that you actually need jQuery for this plugin in the README or documentation - it's very much worth noting for those who do not have it already included.

IE8 fix

Apart from needing some CSS tweaking, this bit needs changing for IE8's benefit:

                $.getJSON(url, function (data) {
                    try {
                        var results = provider.ParseJSON(data);
                        this._processResults(results);
                    }
                    catch (error) {
                        this._printError(error);
                    }
                }.bind(this));

to:

                $.getJSON(url, $.proxy(function (data) {
                    try {
                        var results = provider.ParseJSON(data);
                        this._processResults(results);
                    }
                    catch (error) {
                        this._printError(error);
                    }
                }, this));

I've no idea why, but it seems to fix all IE8's woes.

Demo is not working

When trying to open the demo (linked in Readme.md) at
http://smeijer.github.io/GeoSearch/
no map is displayed.

Inspecting the console shows, that the tile images could not be loaded from http://*.tile.cloudmade.com.

The 403 response message by the server reads: "Forbidden, wrong apikey"

Country?

How should the Country option work? I think I'm expecting it to constrain the search to that country, but that doesn't appear to be what's happening.

Bounding box for search

I modified your code a little bit to hack in a bounding box for the Google geocoding.

I'm not sure how to submit a change thingy, so please let me know if there's a better way to do this.

So, in the file 'l.geosearch.provider.google.js' I modified the start of the getlocations function:

GetLocations: function(qry, callback) {
var geocoder = L.GeoSearch.Provider.Google.Geocoder;
var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-42.9063,147.1335),
new google.maps.LatLng(-42.7167, 147.3444));

    var parameters = L.Util.extend({
        address: qry,
        bounds: bounds
    }, this.options);

This works perfectly. But it's hardcoded, so it would be great to handle it better. (I'm not so good with Javascript yet and don't know how to do it better...)

No license

Without a license there's no indication of how reuse is permitted.

enter key focus

While using this in a custom metabox in a wordpress custom post type screen, I cannot use the Lgeosearch because if you type something in there and press enter key, this activates the wordpress publish post button which also has a keypress listener..

Doesn't work inside a form

HI everyone, I'm facing a problem with L.GeoSearch when the map it's linked to is inside a form. When I hit enter to look for a location, it sends the form... Any idea how this can be solved ? Thanks in advance

GeoSearch with tooltip menu

Hi

I'm a leaflet developer, I wanted you to note the last version of my plug-in Leaflef.Control.Search!
Now support any 3rd party jsonp service and support complete remapping json fields.

This way you can implement geocode serching with tooltip menu and autotyping, in 6 rows:

map.addControl( new L.Control.Search({
        url: 'http://nominatim.openstreetmap.org/search?format=json&q={s}',
        jsonpParam: 'json_callback',
        propertyName: 'display_name',
        propertyLoc: ['lat','lon']
    }) );

Repository

Demos

regards!
Stefano

Preserve appropriate zoom level for search

Just a feature request, it would be nice if geosearch could get the accuracy of the search and zoom to the appropriate level if the geolocator returns that data. For example, if I search for a city name, it should show the city and not a street at the center.

Awesome work!

keypress event not always recognized

I observed that this control's keypress event handler is not reliably triggered in my application (maybe some side effects with other event handlers). At any rate, adding the if (e.keyCode === enterKey) block also to the _onKeyUp handler seems to work much better for me.

Any reason to not hook it into that as well?

Attach GeoSearch to a static DOM element

First: THANKS FOR THE AWESOMENESS!!! This is the easiest and most-comprehensive geocoding library I've seen in three years.

Second: Perhaps it's a bit TOO easy. I'm trying to build an app that buckles bootstrap onto leaflet 5.1 (cartodb.js, actually), and I want to use a static bootstrap <input> tag as the GeoSearch element. This is so I can attach the typeahead function and position the search dialog within the bootstrap-heavy layout. I saw that Sajjad sort of adapted the position thing already, but it doesn't seem to allow for positioning like a static element.

This section of the code where the search box is created programmatically is what's killing me. And my question is this:

If I comment out the above lines, what do I need to do beyond attaching id="leaflet-control-geosearch-qry" to the search input form element? At the moment that doesn't work on its own, and commenting them out just breaks the map with an uncaught typeError.

Demo here

Thanks again!

pass geocode directly to leaflet map .setView() and .marker()

I have an address that is coming from a populated object

I just want to geocode the address, then pass that to the leaflet map .setView() and .marker()

how do i do this

here is my code currently

        var mapStreetAddress = viewModel.get("selectedProperty.streetAddress"),
            mapCity = viewModel.get("selectedProperty.city"),
            mapState = viewModel.get("selectedProperty.state"),
            mapCountry = viewModel.get("selectedProperty.country"),
            mapZipCode = viewModel.get("selectedProperty.zipCode"),
            geoCode = new L.Control.GeoSearch(mapStreetAddress + mapCity + ',' + mapState +  mapCountry + mapZipCode);

        var map = L.map('map',{
            zoomControl: false,
            dragging: false,
            touchZoom: false,
            scrollWheelZoom: false,
            doubleClickZoom : false,
            boxZoom: false,
            tap: false,
            closePopupOnClick: false
        }).setView(geoCode, 18);
        L.tileLayer('http://{s}.tiles.mapbox.com/v3/drkhannah.jn9benmp/{z}/{x}/{y}.png', {
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
        }).addTo(map);
        var marker = L.marker(geoCode).addTo(map);

Issue with Leaflet 0.6.4

When I tried to use the code with the new Leaflet (0.6.4), it would return an error saying: XMLHttpRequest cannot load http://dev.virtualearth/net/REST/v1/Locations?query.... Origin is not allowed by Access-Control-Allow-Origin."

I changed the Leaflet version to 0.4.4, and it worked fine, but I have to use 0.6.4 per company standards. Any suggestions?

Error with example using OpenStreetMap

I get this error when trying to load the example using OpenStreetMap. This is the default example. I can get the example to work when using Google.

l.control.geosearch.js:153 XMLHttpRequest cannot load file://nominatim.openstreetmap.org/search?q=12%20galloway%20cres%20ontario&format=json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.L.Control.GeoSearch.L.Control.extend.sendRequest @ l.control.geosearch.js:153L.Control.GeoSearch.L.Control.extend.geosearch @ l.control.geosearch.js:103L.Control.GeoSearch.L.Control.extend._onKeyUp @ l.control.geosearch.js:233t.(anonymous function).a @ leaflet.js:7

Direct use of Provider doesn't work

This

var googleGeocodeProvider = new L.GeoSearch.Provider.Google(),
  addressText = 'Amsterdam';

googleGeocodeProvider.GetLocations( addressText, function ( data ) {
  // in data are your results with x, y, label and bounds (currently availabel for google maps provider only)
});

causes an error: Cannot read property 'geocode' of undefined at L.GeoSearch.Provider.Google.L.Class.extend.GetLocations.

Google provider loads Google Maps API even if it's already available

In an application that has multiple pages, where you may want to load your map, then switch to another view, then switch back to the map view, calling new L.GeoSearch.Provider.Google() in the GeoSearch constructor options will produce the console error You have included the Google Maps API multiple times on this page. This may cause unexpected errors. because initialize calls loadMapsApi without checking if it's already available. I'll submit a pull request, just wanted to log the issue first.

How to perform search after provider is initialized?

I am trying to use the geosearch during my map initialization. After adding the geosearch control to the map, I programmatically enter an address and kick off a search. The problem is that the search is executed before the onLoadGoogleApiCallback occurs and so there is an error because the L.GeoSearch.Provider.Google.Geocoder is undefined. How or when is the proper time to kick off a geosearch so that I know the provider is completely loaded and ready?

Completely new coding to me. Plz help

I have been using traditional <script> to load geoSearch but it is not working now. I have installed it using npm and don't know what to do. The example in docs is unknown to me. Please helpppppppp. When using <script> and reffering to bundle, css and openstreetmap provider from node module i get following error

jQuery.Deferred exception: L.GeoSearch is undefined
ReferenceError: exports is not defined[Learn More] openStreetMapProvider.js

Im not much used to coding but the <script> used to work then....not now

Publish to npm

I see that this repo already has a package.json, but it's not published to npm. Aside from maybe bumping the version, it seems it'd be just a matter of running npm publish, would be great to be able to access the library from there!

Google Geosearch

Doesn't work, a marker gets placed in the center of the map when I search for a place. The ESRI and the other ones work fine. Do I need an API key for google?

draggable, update longlat after dragging the marker

Hi, i needed to get the new longlat after i dragged the marker, i already set draggable true at geosearch.js

this is my js

      new L.Control.GeoSearch({
              provider: new L.GeoSearch.Provider.Esri()
          }).addTo(m);


        m.on('geosearch_showlocation', (result) => {

        markerLng = result.Location.X;

        markerLat = result.Location.Y;

        });

i understand i must get the dragend something like:

marker.on('dragend', function(event) {
    var marker = event.target;  
    var result = marker.getLatLng(); 
    console.log(result);
});

but i cant find how the name of the created marker

txs!

Add `format` option

Add ad format option to the GeoSearchControl. This format option should be optional; and of type function. It should be invoked with the query and the result, so that one can customize the text in the marker-popup.

Example:

new GeoSearchControl({
  provider: myProvider,           
  showPopup: true,
  popupFormat: ({ query, result }) => `
      q: ${query}<br />
      x: ${result.x}, y: ${result.y}
  `,
});

Google geocoder not working. Invalid key map error

I'm using google geocoder and getting invalid key map error. I referred your demo and developed an application. But gives me Invalid key map error. Should I somewhere mention the googlemaps api key? How can I solve this?

Submit a new release?

Due to the problem reported in #77 , the library, when downloaded through bower is not working correctly if using the google provider.
Since most of the user is going to use such provider, i think that a new release containing that fix would be welcome.

Moving GeoSearch with Provider outside the map?

I'm using https://github.com/smeijer/L.GeoSearch as my search and I'm running into a problem. They have an example of how to move the search out side of the Map but it doesn't use the provider.
At the top you can see the code that is commented out that works with OpenStreetMap but I can't get that into the div that I want. Below it is the code that I can move to where I want but will not search correctly.

How is this done?

`initSearch:function(){
// Adds search to the map and works as it should
// but doesn't add it to the correct div.
// new L.Control.GeoSearch({
// provider: new L.GeoSearch.Provider.OpenStreetMap()
// }).addTo(this.map);

    // Adds search box to the correct div but doesn't provide GeoSearch.
    var markersLayer = new L.LayerGroup();
    this.map.addLayer(markersLayer);

    this.map.addControl( new L.Control.Search({
        container: 'newPRLocationContainer',
        layer: markersLayer,
        initial: false,
        collapsed: false
    }) );

},`

Feature: Possible to clear a search and search marker.

Awesome library, thanks so much.

Wondering if you have considered a way to 'clear' a search. Currently when you search and a location is found a marker is added to the map. The search form is cleared but the marker remains, leaving no way to clear the maker. Thoughts on an option to leave search results in the box with a clear icon or 'x' in the form that would clear the current search text and the marker from the map?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.