新闻中心

将想法与焦点与您共享

Google Flash地图应用
作者:L4cd    来源:L4cd.Net    发布时间:2010-06-21      浏览次数:8033
分享到:

今天网上乱逛的时候..
在一个测试站点速度(http://www.speedtest.cn/)的网站下面~
Google地图显示了访问者所在的位置...
觉得挺有意思的..

看了一下google map的flash api..
实现起来非常方便..感叹一下google map的强大..


swf效果地址:http://blog.l4cd.net/google/googlemap.swf


流程大概这样
1.先获取访客IP,然后通过IP获取用户地理位置信息..(这一步我直接调用了http://www.webxml.com.cn/提供的接口)
2.调用ClientGeocoder.geocode获取该地理位置于google map上的集合..
3.获取第一个位置..用Map.setCenter定位地图..
4.用Map.addOverlay标注位置..
5.用Map.openInfoWindow弹出Tip提示..


code~~

01.<?xml version="1.0" encoding="utf-8"?>
02.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontFamily="Verdana" fontSize="12">
03.    <mx:Script>
04.        <![CDATA[
05.            import com.google.maps.InfoWindowOptions;
06.            import com.google.maps.Map;
07.            import com.google.maps.MapType;
08.            import com.google.maps.overlays.Marker;
09.            import com.google.maps.services.ClientGeocoder;
10.            import com.google.maps.services.GeocodingEvent;
11.             
12.            import mx.controls.Alert;
13.            import mx.rpc.events.FaultEvent;
14.            import mx.rpc.events.ResultEvent;
15.             
16.            private var geocoder:ClientGeocoder;
17.            //by l4cd.net 
18.            private function onMapReady(event:Event):void
19.            {
20.                map.enableContinuousZoom();
21.                map.enableScrollWheelZoom();
22.                geocoder = new ClientGeocoder();
23.                geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS,
24.                    function(event:GeocodingEvent):void {
25.                        var placemarks:Array = event.response.placemarks;
26.                        if (placemarks.length > 0) {
27.                            map.setCenter(placemarks[0].point, 5, MapType.NORMAL_MAP_TYPE);
28.                            var marker:Marker = new Marker(placemarks[0].point);
29.                            map.addOverlay(marker);
30.                            map.openInfoWindow(placemarks[0].point, new InfoWindowOptions({title:"欢迎访问 L4cd.Net 简单工作",content: "来自<"+here+">的访客"}));
31.                        }
32.                    });
33.                geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE,
34.                    function(event:GeocodingEvent):void {
35.                        trace("Geocoding failed");
36.                        Alert.show("获取地理位置失败","L4cd.Net 简单工作");
37.                    });
38.                 
39.                 
40.                ip.getGeoIPContext();
41.            }
42.            private var here:String;
43.            protected function ip_resultHandler(event:ResultEvent):void
44.            {
45.                here = event.result[1];
46.                geocoder.geocode(here);
47.            }
48. 
49.            protected function ip_faultHandler(event:FaultEvent):void
50.            {
51.                Alert.show("获取地理位置失败","L4cd.Net 简单工作");
52.            }
53. 
54.        ]]>
55.    </mx:Script>
56.    <mx:WebService result="ip_resultHandler(event)" fault="ip_faultHandler(event)" wsdl="http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl" id="ip">    
57.    </mx:WebService>
58.    <maps:Map xmlns:maps="com.google.maps.*" language="zh-CN" id="map" mapevent_mapready="onMapReady(event)"
59.              width="100%" height="100%" key="{api_key}"/>
60.</mx:Application>

其中api_key需要你自己到http://code.google.com/intl/zh-CN/apis/maps/signup.html申请一个开发用的key..
只要用google账号登陆..填写你需要使用地图服务的域名即可
当然你可以破解我的flash获取我现在用的key..不过每个key是有域名限制..so..你拿了也没用..

另外此地址为获取访客ip与地理位置的webservice..
http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl

PS~其实把上面的flash稍稍改改..
即可改成显示当前在线用户在地图上的分布..各位兴趣可以尝试一下..

4000-880-989
(24小时热线)
联系客服
微信公众号

官方公众号

小程序

©2008-2022 CORPORATION ALL Rights Reserved. 昆明奥远科技有限公司版权所有 滇ICP备09003328号-1 滇公网安备 53011102000818号 增值电信业务经营许可证号:滇B2-20110045
昆明那家网络公司好,新媒体运营,网站优化,网络推广,网站建设,网页设计,网站设计,网站推广,云南网站公司,昆明新媒体公司,云南网红主播,昆明SEO公司,昆明网站建设,昆明网络推广,昆明网站优化,昆明网站推广,红河网站建设,大理网络公司,曲靖网络公司,丽江网站设计,昭通网络公司,保山大数据服务,智慧高速建设,智慧校园服务,云南IDC服务商,网络安全测评,等保测评,网站关键词排名优化服务,服务客户尽超2000余家,一切尽在奥远科技,服务电话:13888956730