添加静态1公里电网谷歌使用PHP的地图 [英] adding a static 1km grid to google maps using php

查看:132
本文介绍了添加静态1公里电网谷歌使用PHP的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个网格,我会覆盖谷歌地图。
网格具有是静态的,这意味着1km²网格具有在相同的位置,以完全相同并具有可识别与一个唯一的ID。
我怎么能在谷歌地图和PHP实现这一目标?

I want to create a grid that I'll be overlaying google maps. The grid has to be static, meaning 1km² grid has to be exactly at the same location and has to be identifiable with a unique id. How can I achieve this in google maps and php?

最好,
redshark1802

The best, redshark1802

编辑:忘了提,我必须与这些网格照片直接互动,这意味着改变颜色/风格为每个字段。
我发现一些网站,这样做是已经 https://ownthisworld.com/

edit: Forgot to mention that I have to interact with these grids direclty, meaning changing color/style for each field. I've found some site that did it already https://ownthisworld.com/

推荐答案

在回答你的问题都可以在的谷歌地图API(V3)

The answer to your question can be found in the Google Maps API (v3).

这里的基本方法是:


  1. 找到使用的getBounds的 Map对象()方法地图的边界。其结果是一个<一href=\"https://developers.google.com/maps/documentation/javascript/reference#LatLngBounds\">LatLngBounds对象,从中可以提取地图的四角的纬度和经度坐标。

  2. Compute在地图的北部和南部,西部和东部之间(公斤)米的距离。使用这个距离来确定你应该多少行(有1公里的距离)得出。

  3. 画出折线,允许几个形状的网格<一个href=\"https://developers.google.com/maps/documentation/javascript/reference#PolylineOptions\">options被设置,例如像的颜色和宽度。

  4. 如果您也想提醒以及绑定到这些事件的矩形(如你的例子),你可以使用的矩形具有一定的<一个href=\"https://developers.google.com/maps/documentation/javascript/reference#RectangleOptions\">options.您可以绑定'click'事件给这些矩形,这样你可以与它们进行交互。或者你可以使用地图上点击鼠标的坐标来确定单击了哪个方。

  1. Find the bounds of the map using the getBounds() method of the Map object. The result is a LatLngBounds object, from which you can extract the latitude and longitude coordinates of the corners of the map.
  2. Compute the distance in (kilo)meters between the north and south, and west and east of the map. Use this distance to determine how many lines (with distance of 1km) you should draw.
  3. Draw the grid in the shape of PolyLines, which allow for a few options to be set, like for instance color and width.
  4. If you also would like to draw the rectangles with events bound to them (as in your example), you can use a Rectangle with certain options. You can bind 'click' events to these rectangles, such that you can interact with them. Or you could use the coordinates of the mouse click on the map to identify which square was clicked.

扩展信息:
如果你知道在哪里画格,你也知道在哪里画矩形,因为矩形的边缘基本上都是网格线的线段。所以,你怎么知道在哪里画网格线?如果你决定在标准零点(例如当赤道和本初子午线的交汇点),基本上从那里开始绘制网格线,你将永远有定位在相同位置的网格线(和矩形)。请注意,您只画出它们的边界地图的视图内的网格线。
这种方式,也很容易通过例如它的左上角...其将总是位于相同的位置,以确定一个矩形

Extended information: If you know where to draw the grid, you also know where to draw the rectangles since the edges of the rectangles are basically line segments of the grid lines. So how do you know where to draw the grid lines? If you decide on a standard zero point (for instance the point where the equator and prime Meridian meet), and basically start drawing grid lines from there, you will always have the grid lines (and thus rectangles) positioned on the same location. Note, you only draw those grid lines which are within map's view of bounds. This way it is also fairly easy to identify a rectangle by for example it's top left corner...it will always be located on the same position.

这篇关于添加静态1公里电网谷歌使用PHP的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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