maps - get geographical coordinates from address -


i ask user write address , have show on map. know how write script don't know how coordinates having street address. can do?

ps: using leaflet

first have include .js files of geocoder in head of html code, example have used one: https://github.com/perliedman/leaflet-control-geocoder. this:

<script src="control.geocoder.js"></script> 

then have initialize geocoder in .js:

geocoder = new l.control.geocoder.nominatim(); have specify address looking for, can save in variable. example:

var yourquery = (addres of person);     

(you can address out of database, save in variable)

then can use following code 'geocode' address latitude / longitude(coördinates). function return latitude / longitude(coördinates) of address. can save latitude / longitude(coördinates) in variable can use later marker. have add marker map.

geocoder.geocode(yourquery, function(results) {            latlng= new l.latlng(results[0].center.lat, results[0].center.lng);        marker = new l.marker (latlng);        map.addlayer(marker); }); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -