本帖最后由 cnp124858074 于 2009-3-29 19:35 编辑
看到有人需要这个功能
我就把我的整理下发给大家了
演示:www.msenlin.com/home
请不要注册!
第1步
选取默认地图坐标:
首先打开Google地图
ditu.google.cn
在上面寻找一个地址,然后上下左右移动地图,让这个地址正好处于地图的正中心位置,当您想寻找坐标位置已经处于地图的中心位置的时候,拷贝并粘贴以下代码到你的浏览器地址栏:- javascript:void(prompt('',gApplication.getMap().getCenter()));
复制代码 然后回车一下。这时,你将得到一个弹出式的坐标,这个坐标就是你需要找的经度和纬度。
第2步
申请 google map 的 key
http://code.google.com/intl/zh-CN/apis/maps/signup.html
把下面代码里的 红色 换成你的 KEY 跟 坐标就行了
ABQIAAAACoypN5nK6k_TLuhZ3oZH_RSJq63ahCLp9LRODt47kTV4yYcmfRQsX1n-KWWIoMpHFCpMhScWA57t4A
28.189756655197957, 112.99678802490234
第3步
在uchome_spacefield表中添加三个字段,分别为:
lat 类型为 varchar 长度为20
lng 类型为 varchar 长度为20
zoom 类型为 char 长度为3
或SQL直接添加代码:- ALTER TABLE `uchome_spacefield` ADD `lat` varchar(20) NOT NULL AFTER `feedfriend` ;
- ALTER TABLE `uchome_spacefield` ADD `lng` varchar(20) NOT NULL AFTER `lat` ;
- ALTER TABLE `uchome_spacefield` ADD `zoom` char(3) NOT NULL AFTER `lng` ;
复制代码 第4步
在 template 中的 default 中找到 cp_profile.htm 或自己风格摸板
找到:- <tr>
- <th>居住地</th>
- <td>
- <script type="text/javascript">
- <!--
- showprovince('resideprovince', 'residecity', '$space[resideprovince]');
- showcity('residecity', '$space[residecity]', 'resideprovince');
- //-->
- </script>
- </td>
- </tr>
复制代码 在下面添加:- <tr>
- <td colspan="2">
- <input type="button" id="btn_addMarker" disabled value="快添加您在地图上的位置吧,认识更多的朋友" onclick="AddMarker()" class="button" />
- <div id="d_map" style="background-color:#FFF;border:solid 6px gray;width:481px;margin-top:3px;">
- <div style="width:480px; height:300px;background-color:#f3f3f3;" id="map_canvas"></div>
- </div>
- <input type="hidden" name="lng" id="lng" value="$space[lng]" />
- <input type="hidden" name="lat" id="lat" value="$space[lat]" />
- <input type="hidden" name="zoom" id="zoom" value="$space[zoom]" />
- <input type="hidden" name="sid" id="sid" value="$space[uid]" />
- </td>
- </tr>
复制代码 再找到:在上面添加:
- <div class="f_status s_clear">
- <a href="javascript:;" onclick="window.scrollTo(0,0);" id="a_top" title="TOP">TOP</a>
- </div>
- <script src=http://ditu.google.com/maps?file=api&v=2&oe=gb2312&key=ABQIAAAACoypN5nK6k_TLuhZ3oZH_RSJq63ahCLp9LRODt47kTV4yYcmfRQsX1n-KWWIoMpHFCpMhScWA57t4A type="text/javascript"></script>
- <script type="text/javascript">
- var myMap;
- var myMarker;
- var geocoder = null;
- window.onload = function() {
- if (GBrowserIsCompatible()) {
- myMap = new GMap2(document.getElementById("map_canvas"));
- var center = new GLatLng(28.189756655197957, 112.99678802490234); //这个地方就是调整默认显示哪里的,至于里面的经纬度已经再上面给处了获取方法。
- myMap.addControl(new GLargeMapControl());
- myMap.addControl(new GScaleControl());
- myMap.enableScrollWheelZoom();
- geocoder = new GClientGeocoder();
- if (document.getElementById("lat").value == ""){
- myMap.setCenter(center, 16); //这个地方就是可以修改到显示多少级别的,如果想显示到街道级别,把11改为16就差不多了,可以自己//改改看
- document.getElementById("btn_addMarker").disabled = false;
- }
- else{
- var _lat = document.getElementById("lat").value;
- var _lng = document.getElementById("lng").value;
- var _zoom = document.getElementById("zoom").value;
- var _center = new GLatLng(_lat,_lng);
- myMap.setCenter(_center,parseInt(_zoom));
- document.getElementById("btn_addMarker").disabled = true;
- Mark(_lat,_lng);
- }
- }
- }
- function Mark(lat,lng){
- myMarker = new GMarker(new GLatLng(lat,lng), {draggable: true});
- GEvent.addListener(myMarker, "click", function() {
- myMarker.openInfoWindowHtml("<b>把气球拖动到你要标记的地方</b><p>拖动左边的比例尺可以缩放地图</p><a href='javascript:void(0);' onclick='DeleteMarker()'>删除标记</a>");
- });
- GEvent.addListener(myMarker, "dragstart", function() {
- myMarker.closeInfoWindow();
- });
- GEvent.addListener(myMarker, "dragend", function() {
- var gll = myMarker.getLatLng();
- document.getElementById("lat").value = gll.lat();
- document.getElementById("lng").value = gll.lng();
- document.getElementById("zoom").value = myMap.getZoom();
- myMarker.openInfoWindowHtml("<b>把气球拖动到你要标记的地方</b><p>拖动左边的比例尺可以缩放地图</p><a href='javascript:void(0);' onclick='DeleteMarker()'>删除标记</a>");
- });
- myMap.addOverlay(myMarker);
- myMarker.openInfoWindowHtml("<b>把气球拖动到你要标记的地方</b><p>拖动左边的比例尺可以缩放地图</p><a href='javascript:void(0);' onclick='DeleteMarker()'>删除标记</a>");
- }
- function AddMarker(){
- document.getElementById("btn_addMarker").disabled = true;
- var ll = myMap.getCenter();
- document.getElementById("lat").value = ll.lat();
- document.getElementById("lng").value = ll.lng();
- document.getElementById("zoom").value = myMap.getZoom();
- Mark(ll.lat(),ll.lng());
- }
- document.getElementById("residecity").onchange=function AutoMarker(){
- var tmpprovince=document.getElementById("resideprovince").value;
- var tmpcity=document.getElementById("residecity").value;
- var tmpAddress;
- tmpAddress=tmpprovince + tmpcity;
- if (geocoder) {
- geocoder = new GClientGeocoder();
- geocoder.getLatLng(
- tmpAddress,
- function(point) {
- if (!point) {
- alert("iii,Google居然找不到:" + tmpAddress);
- } else {
- document.getElementById("btn_addMarker").disabled = true;
- myMap.clearOverlays()
- Mark(point.y,point.x);
-
- }
- }
- );
- }
- }
- function DeleteMarker(){
- document.getElementById("btn_addMarker").disabled = false;
- myMap.removeOverlay(myMarker);
- var gll = myMarker.getLatLng();
- document.getElementById("lat").value = "";
- document.getElementById("lng").value = "";
- document.getElementById("zoom").value = "";
- }
- </script>
复制代码 第5布
在 template 中的 default 中找到 space_index.htm 或自己风格摸板
找到:- <!--{if $doinglist}-->
- <h2>
- <a href="space.php?uid=$space[uid]&do=doing&view=me" class="r_option">全部</a>
- 记录
- </h2>
复制代码 在上面添加:- <!--{if $space['showprofile']}-->
- <!--{if $space[lat]}-->
- <div id="space_location" class="box">
- <h3>现在位置</h3>
- <p><div style="width:198px;;height:170px;overflow:hidden;border:solid 1px #ccc;" id="map_canvas"></div></p>
- </div>
- <!--{/if}-->
- <!--{/if}-->
复制代码 再找到:在上面添加:- <script src=http://ditu.google.com/maps?file=api&v=2&oe=gb2312&key=ABQIAAAACoypN5nK6k_TLuhZ3oZH_RSJq63ahCLp9LRODt47kTV4yYcmfRQsX1n-KWWIoMpHFCpMhScWA57t4A type="text/javascript"></script>
- <script type="text/javascript">
- window.onload = function() {
- if (GBrowserIsCompatible()) {
- var map = new GMap2(document.getElementById("map_canvas"));
- var center = new GLatLng($space[lat],$space[lng]);
- map.setCenter(center, $space[zoom]);
- var marker = new GMarker(center);
- map.addOverlay(marker);
- }
- }
- </script>
复制代码 第6步
在 source 文件夹中找到 cp_profile.php 文件
找到:- //提交检查
- $setarr = array(
- 'qq' => getstr($_POST['qq'], 20, 1, 1),
- 'msn' => getstr($_POST['msn'], 80, 1, 1),
复制代码 在下面添加:- 'lat' => getstr($_POST['lat'], 20, 1, 1),
- 'lng' => getstr($_POST['lng'], 20, 1, 1),
- 'zoom' => getstr($_POST['zoom'], 3, 1, 1),
复制代码 第7步
在 template 中的 default 中找到 index.htm 或自己风格摸板
在需要显示地图的地方加入下面代码- <div id="div_map">
- <script type="text/javascript">var tmap_u= [];</script>
- <div id="viewmap_index" style="width:520px;height:300px;border:1px solid #ccc;"></div>
-
- </div>
复制代码 在找到:在后面添加:- <div style="display:none;">
- <!--{if $newfeed}-->
- <!--{loop $newfeed $key $value}-->
- <script type="text/javascript">
- tmap_u.push({ "name":"$value[username]","lat": $value[lat], "lng": $value[lng], "id": $value[uid],"zoom": $value[zoom]});</script>
- <div id="map_u_{$key}">
- <span style="float:right;"><a href="space.php?uid=$value[uid]" title="{$_SN[$value[uid]]}" target="_blank"><img src="<!--{avatar($value[uid],small)}-->" class="avatar" /></a></span>
- <p>$value[title_template]</p>
- <p><a href="javascript:map_zoom_in({$key});">放大地图</a> <a href="javascript:map_zoom_out();">还原地图</a> </p>
- <p><a href="space.php?uid=$value[uid]" title="{$_SN[$value[uid]]}" target="_blank">访问 $_SN[$value[uid]] 个人空间</a>
- </p></div>
- <!--{/loop}-->
- <!--{/if}-->
- </div>
- <script src="http://ditu.google.com/maps?file=api&v=2&key=ABQIAAAACoypN5nK6k_TLuhZ3oZH_RSJq63ahCLp9LRODt47kTV4yYcmfRQsX1n-KWWIoMpHFCpMhScWA57t4A" type="text/javascript" charset="utf-8"></script>
- <script type="text/javascript">
- // show shops on map
- var mymap = 'viewmap_index';
- var map = null;
- var mapbounds = new GLatLngBounds(new GLatLng(-33.873801,151.206765), new GLatLng(0.335218,0.719604));
- var markers = [];
- var current_marker = null;
- function map_show_info(i)
- {
- if(current_marker !== i)
- {
- markers[i][0].openInfoWindow(markers[i][1], {"maxWidth": 250});
- current_marker = i;
- }
- }
- function map_zoom_in(i)
- {
- map.setCenter(markers[i][0].getPoint(), 16);
- }
- function map_zoom_out()
- {
- if(current_marker !== null) { markers[current_marker][0].closeInfoWindow(); }
- map.setCenter(mapbounds.getCenter(), Math.min(15, map.getBoundsZoomLevel(mapbounds)));
- }
- function map_set_marker(marker, i)
- {
- GEvent.addListener(marker, "click", function() { map_show_info(i); });
- GEvent.addListener(marker, "infowindowclose", function() { current_marker = null; });
- }
- function map_auto_show()
- {
- var next_marker;
- if(current_marker === null) next_marker = 0;
- else next_marker = current_marker + 1;
- if(next_marker === null || next_marker >= markers.length) { next_marker = 0; }
- map_show_info(next_marker);
- window.setTimeout(map_auto_show, 6000);
- }
- if (GBrowserIsCompatible())
- {
- map = new GMap2(document.getElementById('viewmap_index'));
- map.addControl(new GSmallMapControl());
- map.addControl(new GScaleControl());
- var center = new GLatLng(112.1817398071289,37.20989218842202);
- map.setCenter(center, 12);
-
- for(var i = 0; i < tmap_u.length; i++)
- {
- var icon = new GIcon(G_DEFAULT_ICON, "http://msenlin.com/home/api/td.png");
- G_DEFAULT_ICON.iconSize = new GSize(22, 22);
- icon.iconSize = new GSize(22, 22);
-
- var marker = new GMarker(new GLatLng( tmap_u[i].lat, tmap_u[i].lng ), {"icon": icon, "title": tmap_u[i].name+"@梦森林"});
- map.addOverlay(marker);
- markers.push([marker,document.getElementById("map_u_"+i).innerHTML, tmap_u[i].id]);
- if(markers.length > 1)
- {
- mapbounds =
- new GLatLngBounds(new GLatLng(Math.min(mapbounds.getSouthWest().lat(), tmap_u[i].lat),
- Math.min(mapbounds.getSouthWest().lng(), tmap_u[i].lng)),
- new GLatLng(Math.max(mapbounds.getNorthEast().lat(), tmap_u[i].lat),
- Math.max(mapbounds.getNorthEast().lng(), tmap_u[i].lng)));
- }
- else
- {
- mapbounds = new GLatLngBounds(new GLatLng(tmap_u[i].lat, tmap_u[i].lng),
- new GLatLng(tmap_u[i].lat, tmap_u[i].lng));
- }
- }
- map_zoom_out();
- window.setTimeout(map_auto_show, 3000);
- }
- </script>
复制代码 第8步
在 index.php 文件
找到:- //总会员
- $spacecount = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('space')), 0);
复制代码 在下面加上:- //大家的最新动态
- $newfeed = array();
- $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('feed')." LEFT JOIN " . tname('spacefield') . " ON " .
- tname('feed') . ".uid =" . tname('spacefield') . ".uid WHERE " .tname('feed'). ".friend='0' and " .tname('spacefield'). ".lat != '' ORDER BY dateline DESC LIMIT 0,9");//显示最新动态
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
- realname_set($value['uid'], $value['username']);
-
- $newfeed[] =mkfeed($value);
- /*foreach ($newfeed as $f_index => $tmpfeed) {
- $newfeed[$f_index]['title_template'] = str_replace('{actor}','',$newfeed[$f_index]['title_template']);
- $newfeed[$f_index]['title_template']=stripslashes($newfeed[$f_index]['title_template']);
- $newfeed[$f_index]['title_template'] = preg_replace('/"/','"',$newfeed[$f_index]['title_template']);
- }*/
- }
复制代码 |