将lat / lng坐标转换为给定地图上的像素(使用JavaScript) [英] Conversion of lat/lng coordinates to pixels on a given map (with JavaScript)

查看:215
本文介绍了将lat / lng坐标转换为给定地图上的像素(使用JavaScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将MaxMind中的城市数据库放在一起,它包含数据库中每个城市的lat / lng值。我还整理了一张North / America地图,我希望在地图的x / y坐标上出现一个图标,该图标来自城市数据库记录的纬度/经度坐标。

I have put together a cities database from MaxMind and it includes the lat/lng values for each city in the database. I have also put together a map of North/America and I would like to have a icon appear on the x/y coordinates of the map which are derived from the lat/lng coordinates of the city database record.

根据我的理解,我需要先找到地图的左/上界(lat / lng - > x / y)然后用它作为任何一个之间线性关系的差异北美城市x / y coords。最后,根据地图的大小,只需要几个简单的除法和减法操作来确定放置点的位置。

From my understanding I need to find the left/top bounds of the map first (lat/lng -> x/y) and then use that as a difference for the linear relationship between any of the north american city x/y coords. Finally, depending on the size of the map, its just a few simple division and subtraction operations to figure out where to place the point.

但是我似乎无法弄清楚以下是怎么做的:

However I can't seem to figure out how todo the following:


  1. 我不确定lat / lng映射系统是什么。我如何找到这个?

  2. 如何使用JavaScript库,如何将纬度/经度转换为0,0坐标和每个城市坐标的像素。我尝试过Proj4js,但是它们要求你指定你的坐标图类型等等。这是另一个问类似问题的问题。
    将long / lat转换为像素x / y给定的图片

  1. I'm not sure what the lat/lng mapping system is. How do I find this out?
  2. Using a JavaScript library, how do I convert the lat/lng to pixels for the 0,0 coord and each of the city coords. I've tried Proj4js, but they require that you specify your coordinate map types and so on. Here is another question that asked something similar. Convert long/lat to pixel x/y on a given picture

有任何想法吗?

- 编辑 -

输出地图(北美)是一个连续圆柱:米勒圆柱投影。 http://en.wikipedia.org/wiki/Miller_cylindrical_projection

The output map (of North America) is a continuous cylinder: "Miller cylindrical projection". http://en.wikipedia.org/wiki/Miller_cylindrical_projection

推荐答案

纬度和经度是在地球上绘制的虚线,以便您可以准确地确定世界上的任何位置。简单地说它们是飞机的X和Y坐标。
纬度是一条从北到南的垂直线,北极为90度,南极为-90度。

Latitude and Longitude are imaginary lines drawn on earth so that you can accurately pinpoint any location on the world . simply put they are the X and Y coords of a plane. Latitude is a vertical line running from north to south with its 90 deg at the north pole and -90deg at the south pole.

另一方面经度是一条从东到南的水平线,西边是-180deg,东边是180deg。

Longitude on the other hand is a horizontal line running east to south with -180deg in the west and 180deg in the east.

你可以把latLng转换为像素坐标,因为假设宽度为html容器是世界的宽度,同样适用于高度。

you can convert the latLng into pixel coords as by assuming that the width of the html container is the width of the world and the same applies to the the height.

公式 - 经度 - 像素

(givenLng*widthOfContainerElement)/360

其中360是以度为单位的总经度

公式-Latitude - 像素化

(givenLat*heightOfContainerElement)/180

其中360是度数的总经度

//Height is calculated from the bottom

如果你还是n,请告诉我任何澄清。

let me know if you still need any clarifications.

这篇关于将lat / lng坐标转换为给定地图上的像素(使用JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆