필터 지우기
필터 지우기

Getting coordinates from the webmap at your mouse position

조회 수: 9 (최근 30일)
Daniel
Daniel 2023년 6월 21일
편집: Andrés 2024년 5월 21일
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