2012-09-19 62 views
-1

我已经搜索了网页,我似乎无法找到任何谷歌或Bing地图php类或插件是最新和简单的。谷歌或Bing地图类或插件

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

我打开使用谷歌或Bing地图。有没有人知道任何PHP类/插件,这将有助于实现这一点,而无需手动编写整个功能。

谢谢。

+1

我建议不要使用任何插件。 Google Maps API很容易直接使用,它有很好的文档记录和良好的支持。晦涩的插件引入了比解决问题更多的问题,并且限制了获得支持的机会。不要被“容易”这个词引诱。 :-) – Marcelo

回答

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的全面指南以及大量示例。