Home > Backend Development > PHP Tutorial > 如何用PHP调用google 地图 api ?并且将数据库里经纬度表示的点显示在map下?

如何用PHP调用google 地图 api ?并且将数据库里经纬度表示的点显示在map下?

WBOY
Release: 2016-06-13 12:51:51
Original
1017 people have browsed it

怎么用PHP调用google map api ?并且将数据库里经纬度表示的点显示在地图上??
如题。最好写详细点,谢谢!


------解决方案--------------------
当中 23.1150614,113.4082905  为位置的经纬度。
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="X-UA-Compatible" content="IE=7" /><br />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><br />
<meta name="description" content=" " /><br />
<title>谷歌地图 api测试</title><br />
<style><br />
.map {<br />
<br />
width: 205px;<br />
height: 192px;<br />
text-align: center;<br />
margin: 0 auto;<br />
<br />
}<br />
</style><br />
</head><br />
<body>   <br />
<div id="res_map" class="map"></div><br />
<script src="http://ditu.google.cn/maps?file=api&v=2&&key=ABQIAAAAHDyarwhqc8qoi6Hi4Fw2ABS7hG4ulivpH-Zy5ZAv91XflKVwfhRT3BrS_8CE9kMWp7UXsEngXSYF3A" type="text/javascript" charset="utf-8"></script> <br />
<script type="text/javascript" charset="utf-8">     <br />
function show_small_map() <br />
{ <br />
if (GBrowserIsCompatible()) <br />
{  <br />
var map = new GMap2(document.getElementById("res_map"));<br />
function createMarker(latlng) <br />
{<br />
       var marker = new GMarker(latlng);<br />
       return marker;<br />
}<br />
map.setCenter(new GLatLng(23.1150614,113.4082905), 16);<br />
var smc = new GSmallZoomControl3D;<br />
map.addControl(smc);<br />
var latlng = new GLatLng(23.1150614,113.4082905);<br />
map.addOverlay(createMarker(latlng));  <br />
 <br />
}  <br />
}<br />
show_small_map();<br />
</script><br />
</body><br />
</html>
Copy after login



这个key  要到谷歌上申请 
key=ABQIAAAAHDyarwhqc8qoi6Hi4Fw2ABS7hG4ulivpH-Zy5ZAv91XflKVwfhRT3BrS_8CE9kMWp7UXsEngXSYF3A

本地测试不用key
------解决方案--------------------
引用:
引用:顶顶顶~~~
下面已经可以增加一个标识到地图上,问题是如何将数据库里的所有对应点都加进来呢?script里面又不能引用数据库里的值!!!
PHP code?123456789101112131415161718192021222324252627282930313233343536373839404142434445464……



读数据库  需要懂动态语言基础
------解决方案--------------------
其实最好的办法是从数据库里读出数据,写入一个外部的KML文件里,再用JS载入。
这东西不是三言两语说的清的,代码什么的,最好自己研究,关键是要真正理解。
参考 https://developers.google.com/maps/documentation/javascript/layers
------解决方案--------------------
demo: http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/ggeoxml_loader.html
kml: http://kml.lover.googlepages.com/my-vacation-photos.kml

源码自己研究去吧。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template