369873158
作者369873158·2012-06-11 18:07
技术经理·Infosys

cognos集成google map

字数 3050阅读 3652评论 19赞 17
先看效果图:


RS制作页面布局

实现步骤:
1.在RS中插入一个一行两列的表格,拖入一个HTML项到左边的单元格中,拷贝如下代码到该HTML项中:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<div id="map" style="width: 700px; height: 400px"></div>
<script type="text/javascript">
var latlng = new google.maps.LatLng(40.756, -73.986);
var options = {
    center : latlng,
    zoom : 1,
    mapTypeId : google.maps.MapTypeId.ROADMAP
};

// Creating the map
var map = new google.maps.Map(document.getElementById('map'), options);
var geocoder = new google.maps.Geocoder();
var infowindow;

function displayLocation(a) {
    displayMap(a, 0);
}

function displayInfo(a) {
    displayMap(a, 1);
}

function displayMap(address, displayInfo) {
    geocoder.geocode( {'address' : address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker( {
                map : map,
                position : results[0].geometry.location
            });
            if (!infowindow) {
                infowindow = new google.maps.InfoWindow();
            }
            infowindow.setContent(address);
            if (displayInfo == 1) {
                infowindow.open(map, marker);
            }
        } else {
            // alert("Incorect adress: " +status+address);
        }
    });
}
</script>
2.拖入一个列表到右边的单元格中,然后从Go Sales(query)--->Sales(query)--->Branch中拖入Country、City、Address 1三个数据项到列表中。
3.拖入一个数据项到查询项中,名为Address 2,表达式如下:
replace([Sales (query)].[Branch].[Address 1],'''','''')
4.拖入一个HTML项到列表中的Address 1后面,修改其列表表头为Map,修改其Source Type为报表表达式,然后拷贝下面的代码到该HTML项中:
'<a href="#" onClick="displayInfo( '''+ [Query1].[Address 2]  +', '+[Query1].[City] +', '+[Query1].[Country]+''')">  Show Map</a>
<script>
displayLocation("' + [Query1].[Address 2]  + ', '+[Query1].[City] +', '+[Query1].[Country]+ '");
</script>'
5.选中整个列表,在Properties属性中,将Address 2选中。
6.运行报表,查看结果。

备注:如果代码报这样的错误“geocoder为null或者undefined”,只需要将<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>中的sensor=true改为sensor=false,如果sensor=false报错,改为sensor=true就行啦,自己多试几次就出来了。

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

17

添加新评论19 条评论

369873158369873158技术经理Infosys
2015-05-15 10:15
jjylys: 用Google地图了,是不是得要求报表只能在外网或inter网上运行了,像内网等的 是不是就不能用了呢??
是的啊
jjylysjjylys软件开发工程师xc
2015-05-15 09:19
用Google地图了,是不是得要求报表只能在外网或inter网上运行了,像内网等的 是不是就不能用了呢??
xinxinhuahuaxinxinhuahua软件开发工程师中科软
2014-09-18 10:42
楼主真棒!
keane_kkeane_k软件开发工程师11
2013-12-16 21:45
http得换成https
最爱小丫最爱小丫软件开发工程师新致软件
2013-09-02 16:14
第5步没理解,能解释一下吗
zhu_yizhu_yi软件开发工程师ABC
2013-04-02 00:26
谢谢
369873158369873158技术经理Infosys
2012-11-05 17:29
爱上零点半: 就是不知道除了显示地理位置,还能不能像cognos地图里面那样显示出度量哦????
要显示度量就不是用这个了,要用cognos自带的map功能
爱上零点半爱上零点半软件开发工程师1234
2012-11-05 17:12
就是不知道除了显示地理位置,还能不能像cognos地图里面那样显示出度量哦????
爱上零点半爱上零点半软件开发工程师1234
2012-11-04 16:14
好东西哇
dennisdennisCTO企业IT主管SZTJ
2012-08-16 16:59
good.
bingshanxuefengbingshanxuefeng数据仓库工程师arvato system
2012-08-15 14:02
不错,分享了
meishumeishu软件开发工程师bpcc
2012-07-19 09:51
这个不错
whzj04whzj04软件开发工程师HHJJ
2012-07-16 16:36
不错
贝克汉姆贝克汉姆软件开发工程师IBM
2012-07-04 15:48
369873158: 小贝捧场,料想不到啊
必须的
369873158369873158技术经理Infosys
2012-07-04 14:16
贝克汉姆: 这个不错,分享一下
小贝捧场,料想不到啊
贝克汉姆贝克汉姆软件开发工程师IBM
2012-07-04 11:36
这个不错,分享一下
369873158369873158技术经理Infosys
2012-07-03 18:49
tudouya7626: 为什么我做的说我的位置为定义呢?就是我的address里面写的鸟巢就会说鸟巢未定义
这个你就要去查google map的API,并且有些地图需要自己去借助其他工具去开发,cognos自身的地图功能是很有限的
tudouya7626tudouya7626学生思路
2012-07-03 16:17
为什么我做的说我的位置为定义呢?就是我的address里面写的鸟巢就会说鸟巢未定义
weiyunweiyun软件开发工程师聖嘉科技
2012-06-27 15:33
好心人,謝謝
Ctrl+Enter 发表

作者其他文章

相关问题

相关资料

X社区推广