0

次の境界ボックスがあります。

Left -122.27671
Bottom 37.80445
Right -122.26673
Top 37.81449

また、NE Lat/Long および SW Lat/Long に変換することもできます。

その境界ボックス内で、特定の緯度/経度の X、Y 位置を見つけたいと思います。これは、メルカトル図法を使用します。

メルカトルを使用して世界地図上の位置の X、Y を見つける回答を見たことがありますが、特定の緯度/経度内ではありません。

どんな助けでも大歓迎です!

更新 私が見た別の質問からこれをまとめてください。これが合法と思われる場合、誰でも検証できますか?

map_width = 1240
map_height = 1279

map_lon_left = -122.296916
map_lon_right = -122.243380
map_lon_delta = map_lon_right - map_lon_left

map_lat_bottom = 37.782368
map_lat_bottom_degree = map_lat_bottom * Math::PI / 180

def convert_geo_to_pixel(lat, long)
  x = (long - map_lon_left) * (map_width / map_lon_delta)

  lat = lat * Math::PI / 180
  world_map_width = ((map_width / map_lon_delta) * 360) / (2 * Math::PI)
  map_offset_y = (world_map_width / 2 * Math.log((1 + Math.sin(map_lat_bottom_degree)) / (1 - Math.sin(map_lat_bottom_degree))))
  y = map_height - ((world_map_width / 2 * Math.log((1 + Math.sin(lat)) / (1 - Math.sin(lat)))) - map_offset_y)

  return [x, y]
end
4

2 に答える 2