版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、google 地图和 php+mysql 集合的例子(二)filed under php post by 蜗牛爱吃巧克力 -pp815 / 2011-3-27 10:29 sunday 接着 google 地图和 php+mysql 集合的例子(一) 将数据库的标记显示在地图上面。1、新建个 phpsqlajax_genxml.php文件?php require(conn.php); mysql_query(set names gbk); /使用 gbk 中文编码 ; error_reporting(0); function parsetoxml($htmlstr) $xmlstr=str_r
2、eplace(,>,$xmlstr); $xmlstr=str_replace(,",$xmlstr); $xmlstr=str_replace(,',$xmlstr); $xmlstr=str_replace(&,&,$xmlstr); return $xmlstr; / select all the rows in the markers table $query = select * from markers where 1; $result = mysql_query($query); if (!$result)
3、die(invalid query: . mysql_error(); header(content-type: text/xml;charset=gb2312); / start xml file, echo parent node echo ; / iterate through the rows, printing xml nodes for each while ($row = mysql_fetch_assoc($result) / add to xml document node echo ; / end xml file echo ; ? 2、新建主页 index.html go
4、ogle maps ajax + mysql/php example /!cdata var iconblue = new gicon(); iconblue.image = http:/gmaps- iconblue.shadow = ; iconblue.iconsize = new gsize(32, 32); iconblue.shadowsize = new gsize(22, 20); iconblue.iconanchor = new gpoint(16, 16); iconbwindowanchor = new gpoint(5, 1); var iconred
5、 = new gicon(); iconred.image = http:/gmaps- iconred.shadow = ; iconred.iconsize = new gsize(32, 32); iconred.shadowsize = new gsize(22, 20); iconred.iconanchor = new gpoint(16, 16); iconrwindowanchor = new gpoint(5, 1); var customicons = ; customiconsrestaurant = iconblue; customiconsbar = i
6、conred; var markergroups = restaurant: , bar: ; function load() if (gbrowseriscompatible() var map = new gmap2(document.getelementbyid(map); map.addcontrol(new gsmallmapcontrol(); map.addcontrol(new gmaptypecontrol(); map.setcenter(new glatlng(32.03602,118.795166), 11); gdownloadurl(phpsqlajax_genxm
7、l2.php, function(data) var xml = gxml.parse(data); var markers = xml.documentelement.getelementsbytagname(marker); for (var i = 0; i markers.length; i+) var name = markersi.getattribute(name); var address = markersi.getattribute(address); var type = markersi.getattribute(type); var point = new glatl
8、ng(parsefloat(markersi.getattribute(lat), parsefloat(markersi.getattribute(lng); var marker = createmarker(point, name, address, type); map.addoverlay(marker); ); function createmarker(point, name, address, type) var marker = new labeledmarker(point, icon: customiconstype, labeltext: name, labeloffs
9、et: new gsize(-6, -10); markergroupstype.push(marker); var html = + name + + address; gevent.addlistener(marker, click, function() marker.openinfowindowhtml(html); ); return marker; / 3、另外有个 js 文件 labeledmarker.js,这个文件主要是关于标记样式、信息的, 里面有注释,不过是英文的,呵呵/* * labeledmarker class, v1.2 * * copyright 2007 mi
10、ke purvis (http:/) * * licensed under the apache license, version 2.0 (the license); * you may not use this file except in compliance with the license. * you may obtain a copy of the license at * * /licenses/license-2.0 * * unless required by applicable law or agreed to in writin
11、g, software * distributed under the license is distributed on an as is basis, * without warranties or conditions of any kind, either express or implied. * see the license for the specific language governing permissions and * limitations under the license. * * this class extends the maps apis standar
12、d gmarker class with the ability * to support markers with textual labels. please see articles here: * * http:/ * http:/ */ /* * constructor for labeledmarker, which picks up on strings from the gmarker * options array, and then calls the gmarker constructor. * * param glatlng latlng * param gmarker
13、options named optional arguments: * opt_opts.labeltext string text to place in the overlay div. * opt_opts.labelclass string class to use for the overlay div. * (default labeledmarker_markerlabel) * opt_opts.labeloffset gsize label offset, the x- and y-distance between * the markers latlng and the u
14、pper-left corner of the text div. */ function labeledmarker(latlng, opt_opts) this.latlng_ = latlng; this.opts_ = opt_opts; this.labeltext_ = opt_opts.labeltext | ; this.labelclass_ = opt_opts.labelclass | labeledmarker_markerlabel; this.labeloffset_ = opt_opts.labeloffset | new gsize(0, 0); this.cl
15、ickable_ = opt_opts.clickable | true; this.title_ = opt_opts.title | ; this.labelvisibility_ = true; if (opt_opts.draggable) / this version of labeledmarker doesnt support dragging. opt_opts.draggable = false; gmarker.apply(this, arguments); ; / its a limitation of javascript inheritance that we can
16、t conveniently / inherit from gmarker without having to run its constructor. in order for / the constructor to run, it requires some dummy glatlng. labeledmtotype = new gmarker(new glatlng(0, 0); /* * is called by gmap2s addoverlay method. creates the text div and adds it * to the relevant
17、parent div. * * param gmap2 map the map that has had this labeledmarker added to it. */ labeledmtotype.initialize = function(map) / do the gmarker constructor first. gmtotype.initialize.apply(this, arguments); this.map_ = map; this.div_ = document.createelement(div); this.div_.clas
18、sname = this.labelclass_; this.div_.innerhtml = this.labeltext_; this.div_.style.position = absolute; this.div_.style.cursor = pointer; this.div_.title = this.title_; map.getpane(g_map_marker_pane).appendchild(this.div_); if (this.clickable_) /* * creates a closure for passing events through to the
19、source marker * this is located in here to avoid cluttering the global namespace. * the downside is that the local variables from initialize() continue * to occupy space on the stack. * * param object object to receive event trigger. * param geventlistener event to be triggered. */ function newevent
20、passthru(obj, event) return function() gevent.trigger(obj, event); ; / pass through events fired on the text div to the marker. var eventpassthrus = click, dblclick, mousedown, mouseup, mouseover, mouseout; for(var i = 0; i eventpassthrus.length; i+) var name = eventpassthrusi; gevent.adddomlistener
21、(this.div_, name, neweventpassthru(this, name); ; /* * call the redraw() handler in gmarker and our our redrawlabel() function. * * param boolean force will be true when pixel coordinates need to be recomputed. */ labeledmtotype.redraw = function(force) gmtotype.redraw.apply(this,
22、arguments); this.redrawlabel_(); ; /* * moves the text div based on current projection and zoom level. */ labeledmtotype.redrawlabel_ = function() / calculate the div coordinates of two opposite corners of our bounds to / get the size and position of our rectangle var p = this.map_.fromlatl
23、ngtodivpixel(this.latlng_); var z = goverlay.getzindex(this.latlng_.lat(); / now position our div based on the div coordinates of our bounds this.div_.style.left = (p.x + this.labeloffset_.width) + px; this.div_.style.top = (p.y + this.labeloffset_.height) + px; this.div_.style.zindex = z; / in fron
24、t of the marker ; /* * remove the text div from the map pane, destroy event passthrus, and calls the * default remove() handler in gmarker. */ labeledmtotype.remove = function() gevent.clearinstancelisteners(this.div_); if (this.div_.outerhtml) this.div_.outerhtml = ; /prevent pseudo-leak i
25、n ie if (this.div_.parentnode) this.div_.parentnode.removechild(this.div_); this.div_ = null; gmtotype.remove.apply(this, arguments); ; /* * return a copy of this overlay, for the parent map to duplicate itself in full. this * is part of the overlay interface and is used, for example, to co
26、py everything in the * main view into the mini-map. */ labeledmtotype.copy = function() return new labeledmarker(this.latlng_, this.opts_); ; /* * shows the marker, and shows label if it wasnt hidden. note that this function * triggers the event gmarker.visibilitychanged in case the marker
27、is currently hidden. */ labeledmtotype.show = function() gmtotype.show.apply(this, arguments); if (this.labelvisibility_) this.showlabel(); else this.hidelabel(); ; /* * hides the marker and label if it is currently visible. note that this function * triggers the event gmarker.visibilitychanged in case the marker is currently visible. */ labeledmtotype.hide = function() gmtotype.hide.apply(this, arguments); this.hidelabel(); ; /* * repositions label and marker when setlatlng is called. */ labeledmtotyp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 护肤精油品牌产品介绍
- 肾病征兆解读与护理指南
- 人工加票团队介绍
- 肿瘤护理科普知识
- 直升机基础原理与关键技术解析
- 汽车美容店加盟协议书
- 手机协议书手机版
- 2025-2026学年安徽省铜陵市三年级道德与法治上册期中考试试卷及答案
- 2025年苏课新版五年级地理上册月考考试试题及答案
- 中美协议书哪里
- 牙科社区义诊活动方案
- 小儿中药贴敷治疗讲课件
- 卵巢黄体破裂术后护理查房
- 牙膏包装模型
- T/CECS 10214-2022钢面镁质复合风管
- 学校网评员能力提升培训体系
- 四川省绵阳市2024-2025学年上学期八年级期末数学试卷(含答案)
- 全国统一市政工程预算定额 第8册 路灯工程
- 桥梁涂装专项施工方案
- 园林绿化工程绿化施工法律法规考核试卷
- 【大学课件】证券发行市场
评论
0/150
提交评论