Siva
Siva

Reputation: 1

Set view for an array of addresses(no coordinates) using leaflet js

I don't have latitude and longitude coordinates to set view on leaflet js library. I had an array of objects which contains city and state, country as properties.Now i want to set the markers on the map using leaflet js for this array. What could be the better way to do this?

Upvotes: 0

Views: 1988

Answers (1)

Liedman
Liedman

Reputation: 10329

You need something called a geocoder, that can help you look up the latitude and longitude given the name of a geographic place.

Geocoders are typically quite complicated pieces of software that you run on a server. Fortunately, there are several available that you can use from an HTTP interface, as well as Leaflet plugins to communicate with them.

On Leaflets plugin page (http://leafletjs.com/plugins.html), under the section Geocoding (address lookup), you can find several plugins that might interest you.

For example, you can use Leaflet Control Geocoder (disclaimer: I'm the author of this plugin) that you can either add to the map to let a user search directly, or you can use classes that communicate with the geocoding services directly, to lookup geo coordinates from any string - see for example the class L.Control.Geocoder.Nominatim to use OpenStreetMap's Nominatim geocoding service.

Upvotes: 2

Related Questions