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
0 个评论
回答(1 个)
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!