You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

经纬度转地图屏幕像素算法咨询:拉脱维亚城市定位需求

How to Map Lat/Lon Coordinates to Your Latvia Map's Pixel Positions

Hey there! Let's walk through a straightforward, reliable way to convert those three city coordinates into pixel points you can mark on your static map image. Since Latvia is a relatively small region, we don't need fancy geographic projections—linear mapping will work perfectly here.

Step 1: Get Your Map's Pixel Dimensions

First, note down the exact width and height of your map image (in pixels). You can use any image viewer or editor (like Paint, GIMP, or Photoshop) to find this info. Let's call these values:

  • W: Total width of the map (pixels)
  • H: Total height of the map (pixels)

Step 2: Define Your Map's Geographic Boundaries

Next, you need to figure out the extreme latitudes and longitudes that your map covers. Grab a reference map of Latvia and identify:

  • lat_max: The northernmost latitude shown on your map (highest numerical value, since latitude increases northward)
  • lat_min: The southernmost latitude shown on your map (lowest numerical value)
  • lon_min: The westernmost longitude shown on your map (lowest numerical value, since longitude increases eastward)
  • lon_max: The easternmost longitude shown on your map (highest numerical value)

Pro tip: If you're unsure about the exact boundaries, use a known city (like Riga, at 56.9496, 24.1052)—find its pixel position on your map first, then use that to fine-tune your boundary values if needed.

Step 3: Use the Linear Mapping Formulas

Since screen pixels start at the top-left corner (where y-values increase downward) and latitude increases northward, we need to flip the y-axis calculation. Here are the formulas to convert any (lat, lon) coordinate to (x, y) pixels:

# Calculate x (horizontal) position
x = ((lon - lon_min) / (lon_max - lon_min)) * W

# Calculate y (vertical) position (inverted because latitude increases north)
y = ((lat_max - lat) / (lat_max - lat_min)) * H

Example Calculation

Let's say your map has these placeholder values (adjust based on your actual map):

  • W = 800px, H = 600px
  • lat_max = 57.8, lat_min = 55.6
  • lon_min = 20.9, lon_max = 28.2

Using your first coordinate 57.4093885, 21.5246563:

  • x = ((21.5246563 - 20.9) / (28.2 - 20.9)) * 800 ≈ 68px
  • y = ((57.8 - 57.4093885) / (57.8 - 55.6)) * 600 ≈ 107px

That means you'd mark this city at the (68, 107) pixel position on your map.

Key Notes

  • Decimal coordinates: Your coordinates are already in decimal format (great!), so no need to convert from degrees-minutes-seconds.
  • Accuracy: Linear mapping is more than precise enough for Latvia's size—curvature of the Earth won't affect your pixel positions noticeably.
  • Test with known points: If you have another city with a known pixel position on your map, plug its lat/lon into the formulas to verify your boundary values are correct.

内容的提问来源于stack exchange,提问作者Anton Polst

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:15:30