如何居中&使用 PHP(无 Javascript!)在其标记上缩放 Google 地图 V3?
我有一张谷歌地图,上面显示了几个标记,通常在六个左右。我希望地图能够缩放以适合所有六个标记,并希望也以它们为中心。我正在使用谷歌地图V3。
即使在 Stackoverflow 上,这也不是一个罕见的问题,但我见过的所有解决方案都采用了 Javascript。由于各种原因,我只想使用 PHP,尤其是我拥有与 PHP 一起工作的所有内容,并且不需要在解决方案的一部分中使用其他技术;它很混乱且难以维护。因此,为了清楚起见,让我重复一遍,我正在寻找 PHP 解决方案!
这是我现在所拥有的快照:
// 1st marker
$lat=$_SESSION['map_lat_1']; // latitude
$lng=$_SESSION['map_lng_1']; // longitude
$isclickable='true';
$title=$_SESSION['map_title_1'];
$info=$_SESSION['map_info_1'];
$icon='mapclass/my-marker.png';
$map->addMarker($lat,$lng,$isclickable,$title,$info,$icon);
// 2nd marker
$lat=$_SESSION['map_lat_2']; // latitude
$lng=$_SESSION['map_lng_2']; // longitude
$isclickable='true';
$title=$_SESSION['map_title_2'];
$info=$_SESSION['map_info_2'];
$icon='mapclass/my-marker.png';
$map->addMarker($lat,$lng,$isclickable,$title,$info,$icon);
因此,我使用从众多变量、一些会话变量中获取的数据来调用 addMarker,然后进行调用:
echo $map->showmap();
一切都运行良好。除了我设计的一个非常粗略的“经验法则”算法来尝试猜测缩放级别等。它充其量是命中和错过。我确信必须有一种 PHP 方式来访问附加函数,以将框架和缩放系数设置为任何给定情况所需的任何值,但它们是什么以及它们在方案中的位置?
您的想法将不胜感激!
I have a Google map with several markers displayed, typically around six. I want the map scaled and zoomed to fit all six markers and hopefully centred on them too. I am using Google maps V3.
It's not an uncommon problem, even here on Stackoverflow, but all the solutions I've seen employ Javascript. For various reasons I want to use PHP only, not least of which is I have everything working with PHP and it shouldn't be necessary to use another technology for part of the solution; it's messy and difficult to maintain. So for clarity let me repeat, I am looking for a PHP solution here!
Here's a snapshot of what I have right now:
// 1st marker
$lat=$_SESSION['map_lat_1']; // latitude
$lng=$_SESSION['map_lng_1']; // longitude
$isclickable='true';
$title=$_SESSION['map_title_1'];
$info=$_SESSION['map_info_1'];
$icon='mapclass/my-marker.png';
$map->addMarker($lat,$lng,$isclickable,$title,$info,$icon);
// 2nd marker
$lat=$_SESSION['map_lat_2']; // latitude
$lng=$_SESSION['map_lng_2']; // longitude
$isclickable='true';
$title=$_SESSION['map_title_2'];
$info=$_SESSION['map_info_2'];
$icon='mapclass/my-marker.png';
$map->addMarker($lat,$lng,$isclickable,$title,$info,$icon);
So I feed the calls to addMarker with data garnered from numerous variables, some session variables, then I do the call:
echo $map->showmap();
And it all works well. Except I have a very rough 'rule of thumb' algorithm I devised to try to guess at the zoom level etc. It's hit 'n miss at best. I'm sure there must be a PHP way of accessing additional functions to set the framing and zoom factors to whatever's needed for any given case, but what are they and where do they fit into the scheme of things?
Your thoughts would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论