How do you click on a map and have latitude and longitude fields in a form populated?

前端 未结 4 1317
暖寄归人
暖寄归人 2020-12-03 08:21

I have a form that a user needs to fill out where the location needs to be identified. I have latitude and longitude input fields on the form. I am also looking for the de

4条回答
  •  悲哀的现实
    2020-12-03 09:22

    You will need to know the lat/long of at least TWO points on the map, preferably not very close together, and also know their pixel coordinates relative to one corner (i.e. the best two points would be opposite corners). Then it's simple math to convert the pixel coordinate of the click into lat/long by interpolation. However, note that this works only as long as the area covered by the map is "flat" relative to the Earth's curvature. If the map covered a large area, say 6000 miles wide, there would be significant distortion. If you needed this to be accurate you'd have to do some map projection to calculate the position.

提交回复
热议问题