Google或Bing地图类或插件

时间:2012-09-19 19:13:05

标签: php class google-maps plugins bing-maps

我在网上搜索过,我似乎无法找到任何最新且简单的google或bing map php类或插件。

我正在建立一个房地产搜索网站,我正在寻找一个简单的PHP类,在地图上显示多个地址。我希望找到一个php类或插件,我所要做的就是“requireonce”类/插件和地址,类/插件可以完成所有的工作。

我愿意使用谷歌或bing地图。有没有人知道任何有助于实现这一目标的php类/插件,而无需手动编写整个功能。

谢谢。

1 个答案:

答案 0 :(得分:2)

Google地图和Bing地图是客户端(基于JavaScript),这就是为什么你找不到任何PHP库的原因。

要在地图上显示感兴趣的地点,您需要从数据库中提取项目,然后使用JavaScript将它们添加到地图中。在谷歌地图中,​​这看起来像这样:

// instantiate the map
var map = new google.maps.Map(document.getElementById('map'), {
    center: new google.maps.LatLng(54.673830, -4.746093),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    zoom: 8
});

// create an InfoWindow
var infowindow = new google.maps.InfoWindow();

// fetch results from a PHP script
// assumes results are returned as a JSON-encoded array
$.getJSON('script.php', function(results) {
    $.each(results, function(i, result) {
        // create a market representing place of interest
        var marker = new google.maps.Marker({
            map: map,
            position: new google.maps.LatLng(result.latitude, result.longitude);
            title: result.title
        });

        // display information in infowindow on click
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(result.content);
            infowindow.open(map, marker);
        });
    });
});

希望这会让你开始。查看Google Maps JavaScript API的文档,其中包含API的综合指南以及大量示例。