Getting coordinates from the webmap at your mouse position

6 次查看(过去 30 天)
Hello,
I want to create a map where the user can set a pin and i also want to save the coordinates of the pin afterwards. I tried to work with the webmap and also with geoplot, but both ways dont really work well. A solution would be very appreciated.
Thank you for your help.
Greetings
Daniel

回答(1 个)

Yash
Yash 2023-6-21
You can use the mapping toolbox in MATLAB. I think the geoshow and save function may help (for display and saving). Refer to this code for some more understanding.
%setting up a figure with a Mercator projection for the map
figure
ax = axesm('MapProjection', 'mercator');
set(ax, 'Units', 'normalized', 'Position', [0 0 1 1]);
%set a pin given by user
[lat, lon] = inputm(1);
%display the pin
geoshow(lat, lon, 'Marker', 'o', 'Color', 'red', 'MarkerSize', 10);
%save the pin
save('pin_coordinates.mat', 'lat', 'lon');
%end of code
Hope this helps.
  3 个评论
Yash
Yash 2023-6-22
For this, you can integrate the Leaflet library for MATLAB with the leaflet function and Leaflet's JavaScript capabilities. To start, download and install the Leaflet library for MATLAB from the MATLAB File Exchange and add the library to your MATLAB path. Then download the Leaflet JavaScript library from the official Leaflet website: Leaflet.js and place the Leaflet JavaScript files (leaflet.js and leaflet.css) in the same directory as your MATLAB script. Then run the following MATLAB code.
%Creating map with zoom functionality
map = leaflet('MapCenter', [0, 0], 'ZoomLevel', 2);
%Set pin interactively
marker = addMarker(map, 'Draggable', true);
%Save the coordinates
lat = marker.Lat;
lon = marker.Lon;
save('pin_coordinates.mat', 'lat', 'lon');
%Display the map
map.Visible = true;
Make sure that the Leaflet JavaScript files are properly included in your MATLAB script or project folder for the integration to work correctly.
Andrés
Andrés 2024-5-21
编辑:Andrés 2024-5-21
Where can i obtain the Leaflet library for Matlab?? I can't find it anywhere... And it's not available in the Matlab file exchange...

请先登录,再进行评论。

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by