简体   繁体   English

google maps api v2-动态加载(成千上万个)标记

[英]google maps api v2 - dynamic load (tens of thousands of) markers

how made with JavaScript+PHP+MYSQL and Google Maps API v2 dynamic load of markers? 如何使用JavaScript + PHP + MYSQL和Google Maps API v2动态加载标记?

atm I have map follow example atm我有地图跟随示例

http://googlemapsapi.martinpearman.co.uk/infusions/google_maps_api/basic_page.php?map_id=8 http://googlemapsapi.martinpearman.co.uk/infusions/google_maps_api/basic_page.php?map_id=8

but my marker_data_01.php (where are all markers listed -> look code of example) have atm 4MB and will only have more, and more. 但是我的marker_data_01.php(列出了所有标记->示例的查看代码)的atm为4MB,并且只会越来越多。

So the question is: how load only this markers to marker_data_01.php (of some other modification of it, can be on same file as map, meaningless, I load it all from MySQL atm) 所以问题是:如何仅将这些标记加载到marker_data_01.php (对其进行的其他一些修改,可以将其与map放在同一文件上,这毫无意义,我全部从MySQL atm加载了)

what I look now: 我现在的样子:
so for example (I dont know what number will good but I write this only for show what I wanna made OR JUST something like it), so 因此, 例如 (我不知道哪个数字会很好,但是我写这个只是为了显示我想做的,或者仅仅是这样),所以

  • top left corner for example have position: 10, 例如,左上角的位置是:10,
  • top right corner for example have position: 30, 例如,右上角的位置为30,
  • bottom left corner for example have position: 5, 例如,左下角的位置为:5
  • bottom right corner for example have position: 15. 例如,右下角的位置为:15。

-- so load only this markers what are in this box 10-30-5-15 -因此仅加载此标记此框中的内容10-30-5-15

with for example GET, 例如GET

and when I move map for example to 17-12-48-20 box then made next GET request 当我将地图移动到17-12-48-20框时,然后发出下一个GET请求
and with this mysql quote and download next markers that what I see now, 并使用此mysql报价并下载我现在看到的下一个标记,

with this I can have map with unlimited markers, 有了这个,我可以有无限标记的地图,

and when will be a lot of markers then clustering can link them, 何时会有很多标记,然后聚类可以将它们链接起来,

so with this ppl dont will need do "preload" of all markers DB (what have 4mb now and will have more), but only download that what they see at the moment, 因此使用此ppl时,不需要“预加载”所有标记数据库(现在有4mb,并且将会有更多),但仅下载他们目前看到的内容,

I know that is possible because a lot sites have it but I am not master of code langs, I know only a bit php and mysql (and html) :) 我知道这是可能的,因为很多网站都有它,但是我不是代码语言的高手,我只知道一点php和mysql(和html):)

// sorry for my english // 对不起我的英语不好

Seems to me that you're looking for something like MarkerClusterer 在我看来,您正在寻找诸如MarkerClusterer之类的东西

EDIT 编辑

I see - I didn't get the original ask very clearly. 我知道了-我没有很清楚地收到原始要求。

What you need to do is send the current lat/lon box to the server, and use those values in your WHERE clause. 您需要做的是将当前的经/纬度框发送到服务器,并在WHERE子句中使用这些值。

Here's a quick example 这是一个简单的例子

// Create a GMap2 instance
var gmap = new GMap2( document.getElementById( 'map' );

// Do all your setup here, like gmap.setCenter() and such

// Now, load the map data
loadMapFromCurrentBounds( gmap );

// Assign a handler to the "moveend" event
GEvent.addListener( gmap, 'moveend', function()
{
  loadMapFromCurrentBounds( gmap );
});

function loadMapFromCurrentBounds( gmap )
{
  // First, determine the map bounds
  var bounds = gmap.getBounds();

  // Then the points
  var swPoint = bounds.getSouthWest();
  var nePoint = bounds.getNorthEast();

  // Now, each individual coordinate
  var swLat = swPoint.lat();
  var swLng = swPoint.lng();
  var neLat = nePoint.lat();
  var neLng = nePoint.lng();

  // Now, build a query-string to represent this data
  var qs = 'swLat=' + swLat + '&swLng=' + swLng + '&neLat=' + neLat + '&neLng=' + neLng;

  // Now you can use this query-string in your AJAX request  

  // AJAX-stuff here
}

And then, on the PHP end, assuming your data table has a lat and lng column, something like this 然后,在PHP端,假设您的数据表具有latlng列,如下所示

$swLat = mysql_real_escape_string( $_GET['swLat'] );
$swLng = mysql_real_escape_string( $_GET['swLng'] );
$neLat = mysql_real_escape_string( $_GET['neLat'] );
$neLng = mysql_real_escape_string( $_GET['neLng'] );

$query = "
SELECT *
  FROM [Table]
 WHERE lat > $swLat
   AND lat < $neLat
   AND lng > $swLng
   AND lng < $neLng
";

You won't be able to manage/display thousands of markers on google maps using Marker Manager, the performance will be atrocious. 您将无法使用“标记管理器”在Google地图上管理/显示成千上万个标记,因此性能将非常糟糕。 The only way to do this with any reliability is to use either a utility like MarkerClusterer, which groups markers in close proximity together, or use a Fusion Tables Layer. 做到任何可靠性的唯一方法是使用MarkerClusterer之类的实用程序,该实用程序将标记紧密地分组在一起,或者使用Fusion Tables Layer。

I personally would recommend the Fusion Tables Layer, however there is a great writeup here that talks about all of the different options that you might want to consider. 我个人会推荐Fusion Tables层,但是这里有一篇很棒的文章,讨论了您可能要考虑的所有不同选项。 https://developers.google.com/maps/articles/toomanymarkers https://developers.google.com/maps/articles/toomanymarkers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM