Thursday, 29 January 2015

Google Map in Cognos Report




Use Google Map into Cognos Report


  • Launch Report Studio. When prompted, select the Go Sales(query) package and a new list report template.
  • Expand the Sales (query) namespace and drag Country, City etc.
  • From the Insertable Objects tab, drag 4 HTML items into the City data item (unlock cell first) and 1 HTML where you want to show Map.


  • Open HTML items and insert the mentioned code.
  • HTML1: <div onClick="AddMarker('
  • HTML2: Change the Source type to “Report Expression” and drag City from query.
  • HTML3: ')">
  • HTML4: </div>
  • Click Ok.
  • HTML5:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></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 marker= new google.maps.Marker(null);
function AddMarker(address)
{
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 });
var infowindow;
if (!infowindow)
{
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent(address);
google.maps.event.addListener(marker, 'click', function()
{
infowindow.open(map,marker);
});
}
});
}
</script>

  • Run the report, it will generate the output like below.




  • Click on any City to get marker.

13 comments:

  1. Hi! I respect all your procedure described above. The map is appiring ,but when i'm clicking on my city , the marker doesn't appear. Do you have any idea why? Thx a lot!

    ReplyDelete
  2. Hi

    I cant get this to work.
    I've followed exactly, and yet keep getting an error 'ReferenceError: AddMarker not defined' when I click on a City in the list. ??

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. hello, I do not know if this will still interest anyone, for the error resolution reported above, you should do the following actions in IBM Cognos report Studio:
    - select the report, then go to the report properties;
    - look for the option: perform with integral interactivity;
    - Change this to: no;
    - save the report and run it again;

    ReplyDelete
  6. Carlos , pudieras enviarme la especificación del reporte a mi correo

    jaime.hdz.gt@gmail.com

    ReplyDelete