Latitudes and longitudes of mouseclick in openstreetmap.

1 vue (au cours des 30 derniers jours)
Damian Godlewski
Damian Godlewski le 21 Avr 2021
Réponse apportée : Jaynik le 13 Oct 2023
How can I get latitudues and longitudues of mouseclick in openstreetmap?. Is it possible? I tried inputm but it doesn't work or I did something wrong.

Réponses (1)

Jaynik
Jaynik le 13 Oct 2023
Hi Damian,
I understand that you want to obtain the latitude and longitude of a location through mouseclick for a map in the “openstreetmap” format.
Assuming that you are using an “osm” file, in the latest release R2023b, you can use the “readgeotable” function to open such files. Then, you can create and use a callback function to obtain the coordinates on mouse click. Following is the code to perform the same:
osm = readgeotable('sample.osm');
geoshow(osm);
dcm_obj = datacursormode(gcf);
set(dcm_obj, 'UpdateFcn', @getLatLon);
function output_txt = getLatLon(~, event_obj)
pos = get(event_obj, 'Position');
lat = pos(2);
lon = pos(1);
output_txt = {['Latitude: ' num2str(lat)], ['Longitude: ' num2str(lon)]};
end
You can read more about “readgeotable” here:
Hope this helps!

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by