Ive successfully created a map, marker and infobubble that uses values from reverse geocoding method. With 1 location, the map works fine and displays the marker and info bubble accordingly. However when i pass two location values from the backend (i am using jsp) the map does not render.
Functions I use are: addMarkerToGroup, addInfoBubble, onSuccess,
function addMarkerToGroup(group, position, inf){
var marker = new H.map.Marker(position);
//add custom data to marker
marker.setData(inf);
group.addObject(marker);
}
function addInfoBubble(position,inf){
var group = set_map.group;
var map = set_map.map;
var ui = set_map.ui;
map.addObject(group);
//add 'tap' event listener, that opens info bubble, to the group
group.addEventListener('tap', function(evt){
//event target is the marker itself, group is a parent event target
var bubble = new H.ui.InfoBubble(evt.target.getPosition(),{
// read custom data
content: evt.target.getData()
});
//show info bubble
ui.addBubble(bubble);
}, false);
addMarkerToGroup(group,position,inf);
}
function callback(){
var platform = new H.service.Platform({
app_id: '#',
app_code: '#',
useCIT: true,
useHTTPS: true
});
var defaultLayers = platform.createDefaultLayers();
var obj = your_location.map_obj;
var map = new H.Map(
obj,
defaultLayers.normal.map,
{
zoom:your_location.map_zoom,
center: {lat:your_location.latitude,lng:your_location.longitude}
});
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
var ui = H.ui.UI.createDefault(map, defaultLayers);
var group = new H.map.Group();
}
function onSuccess(result){
var index = your.count;
var myclt = your.get_yours(index);
var myttl = your.get_title(index);
var myinf = your.get_info(index);
var location = result.Response.View[0].Result[0];
var countryName, countryCode, province, city, zipcode;
countryName = location.Location.Address.Country;
countryCode = location.Location.Address.Country;
province = location.Location.Address.State;
zipcode = location.Location.Address.PostalCode;
city = location.Location.Address.City;
var address = "";
if (city && city != "") {
address = city;
}
if (province && province != "") {
if (address && address != "") {
address += ", " + province;
} else {
address = province;
}
}
if (zipcode && zipcode != "") {
if (address && address != "") {
address += ", " + zipcode;
} else {
address = zipcode;
}
}
if (countryName && countryName != "") {
if (address && address != "") {
address += ", " + countryName;
} else {
address = countryName;
}
}
$.ajax({
url: "view_remote_device_control.do",
data: {
mode: "update",
client_id: myclt,
city: city,
province: province,
zipcode: zipcode,
country: countryCode
},
type: "GET",
cache: false,
async: true
});
myttl += address;
var position = new H.geo.Point(location.Location.DisplayPosition.Latitude,location.Location.DisplayPosition.Longitude);
var inf = {content: location.Location.Address.Label};
var myinfo = inf.content;
addInfoBubble(here_maps_callback.map,position,inf.content,here_maps_callback.ui);
return myinf;
};
While debugging I get the error:
Uncaught InvalidArgumentError: H.map.ViewModel#setCameraData (Argument #0 position)
Okay, so i realized that it the reason why it was not rendering was due to:
center: {lat:your_location.latitude,lng:your_location.longitude}
Basically due to passing two location values, the location array had two values for both latitude and longitude and it did not know which to use to set the center. By changing both the values of lat and lng to 0 and using:
map.setCenter(evt.target.getPosition());
inside the group event listener it rendered the map accordingly.
Hope this is helpful
A bit confused how is the callback is happening, where are the two location finally retrieved on the JavaScript side ? Do you face the issue if you directly pass the locations in javascript , i mean hard coded as a test ?
Related
Currently i am able to display 3 route of 3 drivers respectively(one for each) on a single Gmap.
Now, I wish to show route of 'n' number of drivers (single route for each driver)on Gmap. Its a case of dynamic drivers. I can get data from db for 'n' number of drivers that i need to display on a single map.
My Code is below for single driver please help me for dynamic craetion of routes:
var lat_lng1 = [];
var latlngbounds1 = "";
lat_lng1 = new Array();
var value1 = markers1.length;
//Intialize the Path Array
var path1 = new google.maps.MVCArray();
//Intialize the Direction Service
var service1 = new google.maps.DirectionsService();
var lineSymbol1 = { path1: google.maps.SymbolPath.CIRCLE };
//Set the Path Stroke Color
for (i = 0; i < markers1.length; i++) {
var data1 = markers1[i]
var myLatlng1 = new google.maps.LatLng(data1.lat, data1.lng);
lat_lng1.push(myLatlng1);
var marker1 = new google.maps.Marker({position: myLatlng1,map: map,icon: icon1});
(function (marker1, data1) {
// Attaching a click event to the current marker
google.maps.event.addListener(marker1, "click", function (e) {
if (i == 0){
infoWindow.setContent(data1.Person);infoWindow.open(map, marker1);}
if(i=(markers2.length -1)){
infoWindow.setContent(data1.Person);infoWindow.open(map, marker1);}
else{
infoWindow.setContent(data1.Title);
infoWindow.open(map, marker1);}
});
})(marker1, data1);
}
poly = new google.maps.Polyline({
// path: lineCoordinates,
strokeColor: '#BC456F',
icons: [{
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,strokeColor: '#009900',fillColor: '#009900',fillOpacity: 1},
repeat: '100px',
path1: []
}],
map: map
});
well I solved this issue the very next day by calling ajax loops by driver id
I should have on my hands what is proper working JS and an xml file...I'm simply trying to take advantage of the huge database of locations that has been offered up as free for everyone to use - located # http://www.craftbeer.com/breweries/brewery-locator/find-a-us-brewery
I'm tried using their maps.js and xml file...but all I end up with is a blank maps screen...
Here is the Javascript...
/*********************************************
**Google Maps Custom API work**
This code can be reused on any site to display a local map of breweries from our local iMis dump, as well as pull in beermapping.
Hey! Don't forget to include API in functions.php! Function is conditionally initialized in footer.php
*/
//Set up variables to create marker
var gmarkers = [];
var mapMarkers = [];
var geocoder = new google.maps.Geocoder();
var icon = 'http://www.craftbeer.com/wp-content/uploads/marker.png';
//Initialize Map
function view_map(xml_file, latitude, longitude, varZoom) {
console.log('view map');
map = new google.maps.Map(document.getElementById("map_canvas"), { //Create the map, Set Default Zoom level and type
center: new google.maps.LatLng(latitude, longitude),
zoom: varZoom,
mapTypeId: 'roadmap',
panControl: true,
zoomControl: true,
mapTypeControl: false,
scaleControl: true,
streetViewControl: false,
overviewMapControl: false
});
//-- Listeners --//
google.maps.event.addListener(map, 'center_changed', function() {
console.log('center changed');
//clearMarkers();
});
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
//this part runs when the mapobject is created and rendered
console.log("loaded");
$("#loading-screen").fadeOut(250, function(){});
$("#loading-icon").fadeOut();
//google.maps.event.addListenerOnce(map, 'tilesloaded', function(){ });
});
//console.log(xml_file);
var download_file = xml_file; //this variable is passed in so we can re-use this script
//Pull in the XML feed
downloadUrl(download_file, function(data) {
console.log("downloading xml");
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
//Loop through all markers in the XML file
for (var i = 0; i < markers.length; i++) {
var state = markers[i].getAttribute("state");
var x = markers[i].getAttribute("lat");
var y = markers[i].getAttribute("lng");
if ( state != 'PR' && state != 'VI' && state != 'GU' && x != "" ){
//console.log(state);
var ids = parseFloat(markers[i].getAttribute("id"));
var z = new google.maps.LatLng(x,y,i);
//console.log(x);
var _id = markers[i].getAttribute("id");
var name = markers[i].getAttribute("company");
var address = markers[i].getAttribute("address");
var city = markers[i].getAttribute("city");
var zip = markers[i].getAttribute("zip");
var phone = markers[i].getAttribute("phone");
var url = markers[i].getAttribute("url");
var brewery_type = markers[i].getAttribute("type");
var member_type = '';
var member_type = markers[i].getAttribute("member_type");
var offer = markers[i].getAttribute("offer");
var html = "<div class='bubble_content'><strong>" + name + "</strong><br />";
html += address + "<br/>" + city + ", " + state + " " + zip;
if(url) html += "<br /><br /><a href='http://" + url + "' target='_blank'>Visit Web Site</a></div>";
//var marker = createMarker(ids, z, title, contentstring);
var marker = new google.maps.Marker({
position: z,
map: map,
title: name,
icon: icon,
html: html,
zindex: i
});
//Add a listener for every icon click
google.maps.event.addListener(marker,'click',function(){
infowindow.setContent(this.html);
infowindow.open(map,this);
//map.setZoom(10);
//map.setCenter(this.getPosition());
console.log(this);
});
gmarkers[ids] = marker;
mapMarkers.push(marker);
if( x && y ){
//console.log(ids);
var infowindow = new google.maps.InfoWindow({content: html});
}
/* google.maps.event.addListener(marker, 'click', function() {
console.log('marker clicked');
});
*/
//bounds.extend(z);
//map.fitBounds(bounds);
}//end check for US states only!
} //end for loop
var mcOptions = {gridSize: 60, maxZoom: 9};
var markerCluster = new MarkerClusterer(map, mapMarkers, mcOptions); //this is the function that groups the icons into markers
});
} //End full function to create map
/*
* FUNCTION
*
* click to bring up one icon when clicked from the list.
*/
function myclick(i){
console.log('clicked a title ' + i);
smoothScroll("#primary");
var lat = parseFloat(gmarkers[i].position.k);
var lng = parseFloat(gmarkers[i].position.B);
console.log(lat);
map.setCenter({lat: lat, lng: lng});
map.setZoom(13);
google.maps.event.trigger(gmarkers[i], 'click');
};
function createMarker(ids, z, title, contentstring){
console.log('createMarker');
var marker = new google.maps.Marker({
position: z,
map: map,
title: title,
html: contentstring,
icon: 'http://maps.google.com/mapfiles/ms/icons/orange-dot.png'
});
google.maps.event.addListener(marker,'click',function(){
infowindow.setContent(this.html);
infowindow.open(map,marker);
});
gmarkers[ids] = marker;
//console.log(gmarkers[ids]);
};
/*
* FUNCTION findAddress()
*
* given an adress string, zoom the map to the proper state
*/
function findAddress(position) {
//Let's determind if we have a state (address) or LatLng
var addressStr = $("#state_select li.active").data('state-id');
if (addressStr != 'Select a State') address = "US State of "+addressStr;
if(position) {
var lat = parseFloat(position['latitude']);
var lng = parseFloat(position['longitude']);
var latlng = new google.maps.LatLng(lat, lng);
//console.log(latlng);
}
//Now let's geocode - two different cases
if (geocoder && position) { //If LatLng
//console.log('near me');
geocoder.geocode( { 'location': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
if (results && results[0] && results[0].geometry && results[0].geometry.viewport && addressStr!="ON" && addressStr!="INT") {
map.fitBounds(results[0].geometry.viewport); //resize map to fit.
map.setZoom(13);
}
} else {
alert("No results found");
}
}
});
} else if (geocoder && address!="") { //If State
//console.log('by state');
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
if (results && results[0] && results[0].geometry && results[0].geometry.viewport && addressStr!="ON" && addressStr!="INT") {
map.fitBounds(results[0].geometry.viewport); //resize map to fit.
map.setZoom(6);
}
} else {
alert("No results found");
}
}
});
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
And here is the link to the xml file....
http://www.straighttothepint.com/wp-content/uploads/wp-google-maps/Google_Map_APIs.xml
I've spent days doing google searches and testing different sections of code to at least get a basic google map to show up via the xml file markers...but to no avail - Any help would be tremendously appreciated!!
~Cheers
EDIT:
Everything worked as expected once I included the following script inline on the page prior to calling the maps.js file. Thanks everyone!
<script>
$(document).ready(function(){
var latitude = 39.300299;
var longitude = -97.382812;
view_map('./uploads/your_xml_file.xml', latitude,longitude,4);
//scripts to handle mapping are in js/mylibs/map.js.php
});
</script>
Looking at the html and the code you provided above I constructed a fiddle for you:
http://jsfiddle.net/loanburger/qafsex5x/
I added two markers in an xml string at the top in the fiddle.
I basically parse the xml doing this:
var markers = $(xml).find("marker");
Its then simply the same for loop you had:
for (var i = 0; i < markers.length; i++)
{
...
}
The fiddle will show you the markers.
I’m having problems upgrading to Google Maps v3 from v2. In particular with MarkerManager. I haven’t worked with maps before and am helping out someone whose developer abandoned them who developed the maps in v2.
The map is to show a maximum of 100 markers that when clicked on show an infobox. (There is also a telerik RadGrid bound to with the results.) It all seems to work until it gets into DisplayAllMarkers() mgr.addMarkers() (see below). It fails in ProjectionHelperOverlay.prototype.LatLngToPixel with Uncaught TypeError: Cannot call method ‘lng’ of undefined. I’ve tried putting in alerts in AddMarker if lat or lng are undefined, but none were alerted. The previous calls to MarkerManager.prototype.addMarkerBatch_ set mPoint to undefined which was then passed to getTilePoint which calls LatLngToPixel where it fails.
I’m thinking it’s a problem with listeners, but have tried various listeners without success. I would really appreciate some help with this as I have been unable to make progress for some time and am letting down the client and don’t know what to try next.
Select SearchResult.js snippet of code:
$(document).ready(function () {
InitializeMap(originalScale);
});
var map;
var batch = [];
var mgr;
var geocoder = null;
function InitializeMap(scale) {
map = new google.maps.Map(
document.getElementById('MapContainer'), {
center: new google.maps.LatLng(Latitude, Longitude),
zoom: scale,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false
});
var listener = google.maps.event.addListener(map, "bounds_changed", function () {
MapMoved();
google.maps.event.removeListener(listener);
});
}
var south, west, north, east, zoom;
function MapMoved() {
zoom = map.getZoom();
//zoom = map.setZoom();
var bounds = map.getBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
south = sw.lat();
west = sw.lng();
north = ne.lat();
east = ne.lng();
Search();
}
The Search(); loads up the search parameters (including the north, south, east, west co-ordinates) and calls a telerik ajax request.
C# snippet:
if (Properties.Count >= 1 || zoom == "0") //display properties
{
RadAjaxManager1.ResponseScripts.Add("ClearAll();");
Properties.ForEach(p =>
{
string script = "AddMarker(" + p.ID.ToString() + "," + p.LatitudeShort.ToString() + "," + p.LongitudeShort.ToString() + ");";
RadAjaxManager1.ResponseScripts.Add(script);
});
RadAjaxManager1.ResponseScripts.Add("DisplayAllMarkers();");
}
else //zoom out map – which will start the search process all over again.
{
string delta = "1";
RadAjaxManager1.ResponseScripts.Add("ZoomOut(" + delta + ");");
}
SearchResult.js snippet continued:
function ClearAll() {
batch = [];
}
function AddMarker(id, lat, lng) {
batch.push(CreatePropertyMarker(lat, lng, id));
}
function DisplayAllMarkers() {
mgr = new MarkerManager(map, { trackMarkers: true });
google.maps.event.addListener(mgr, 'loaded', function () {
mgr.clearMarkers();
mgr.addMarkers(batch, 3, 17); // **Failing in here!!!**
mgr.refresh();
});
}
function CreatePropertyMarker(lat, lng, id) {
var redIcon3 = {
url: '../images/HouseIcon_ForGoogleMap.png',
size: new google.maps.Size(22, 22),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(0, 22)
};
var marker3 = new google.maps.Marker(new google.maps.LatLng(lat, lng), redIcon3);
google.maps.event.addListener(marker3, 'click', function () {
var data = "{'Id': '" + id + "'}";
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
url: 'searchresult.aspx/GetPropertyPopOut',
data: data,
success: function (data) {
var popout = data.d;
marker3.openExtInfoWindow(map, "custom_info_window_red", popout, { beakOffset: -1 });
},
error: function (result) {
alert('status:' + result.status + ' statusText:' + result.statusText);
}
});
});
return marker3;
}
Script order and versions:
jquery-ui-1.9.1.custom.min.css
Google Maps: v3 (I have also tried specifying particular version 3 numbers e.g. v=3.12 http://maps.googleapis.com/maps/api/js?key=MY_KEY&sensor=false
jquery-1.8.2.js
jquery-ui-1.9.1.custom.min.js
extinfowindow.js v2.0
MarkerManager.js v1.1
SearchResult.js
jquery-ui-1.8.16.custom.min.js
jquery-1.6.2.min.js
After tying a load of different things I eventually found out the problem was when creating the marker it needed position set. I changed the line in CreatePropertyMarker from:
var marker3 = new google.maps.Marker(new google.maps.LatLng(lat, lng), redIcon3);
to:
var marker3 = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
icon: redIcon3
});
I have the following code which is successfully plotting a route between two points. However I wish to search a recordset to see which georeferences lie within a range of this route. E.g. 50 yards off the main route
function plot_route() {
var rendererOptions = { map: map };
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
var org = new google.maps.LatLng ( $("#start_lat").html(), $("#start_long").html() );
var dest = new google.maps.LatLng ( $("#finish_lat").html(), $("#finish_long").html() );
if ($("#via_lat").html() != "") {
var point1 = new google.maps.LatLng($("#via_lat").html(), $("#via_long").html());
}
else
{
point1 = dest;
}
var wps = [{ location: point1 }];
if (($("#start_lat").html() != "") && ($("#finish_lat").html() != "")) {
var request = {
origin: org,
destination: dest,
waypoints: wps,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
else
alert ('failed to get directions');
});
}
}
I have tried breaking down the response but it shows that the calculation does not return an array of values to make up the route.
Has anyone conquered this one before?
edit
Digging Deeper, it seems the response does contain the array of route points. For those in the community who are looking for help rather than contributions from people gung ho with the -1 button i attach the following
function plot_route() {
var rendererOptions = { map: map };
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
var org = new google.maps.LatLng ( $("#start_lat").html(), $("#start_long").html() );
var dest = new google.maps.LatLng ( $("#finish_lat").html(), $("#finish_long").html() );
if ($("#via_lat").html() != "") {
var point1 = new google.maps.LatLng($("#via_lat").html(), $("#via_long").html());
}
else
{
point1 = dest;
}
var wps = [{ location: point1 }];
if (($("#start_lat").html() != "") && ($("#finish_lat").html() != "")) {
var request = {
origin: org,
destination: dest,
waypoints: wps,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var myroute = response.routes[0];
if(myroute)
{
$.each(myroute, function(key, value) {
if (key == "overview_path") {
alert(value); //the array of points for the route
}
});
}
directionsDisplay.setDirections(response);
}
else
alert ('failed to get directions');
});
}
}
hope this makes sense. I have merged together two tables one containing information about telephone exchanges and their specific location in the uk and another containing region info for the uk. What I want to do is when I roll over or click on a region I want to be able to list all the exchanges that fall into that area on a panel on my web page. At the moment when I click on a region the last exchange in the table is displayed. I'm guessing this could be something simple that I need to do within my addListeners2() function. Any pointers in the right direction would be greatly appreciated.
var map, layer;
function initialize()
{
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(54.54658,-4.87793),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
loadPoint();
}
function loadPoint()
{
if (layer != null)
{
layer.setMap(null);
google.maps.event.clearInstanceListeners(layer);
}
var tableid = '3569550';
layer = new google.maps.FusionTablesLayer
({
query:
{
select: 'LATITUDE',
from: tableid
//where: 'latitude is not null'
},
map: map
})
layer.enableMapTips({
select: "'REGION','EXCHANGE','MPF','WLR','SMPF','BB_CONNECT'", // list of columns to query, typially need only one column.
from: tableid, // fusion table name
geometryColumn: 'LATITUDE', // geometry column name
suppressMapTips: true, // optional, whether to show map tips. default false
delay: 100, // milliseconds mouse pause before send a server query. default 300.
tolerance: 8 // tolerance in pixel around mouse. default is 6.
});
addListeners1();
}
function loadRegion()
{
if (layer != null)
{
layer.setMap(null);
google.maps.event.clearInstanceListeners(layer);
}
var tableid = '3569550';
layer = new google.maps.FusionTablesLayer
({
query:
{
select: 'geometry',
from: tableid
},
map: map
})
layer.enableMapTips({
select: "'REGION','EXCHANGE','MPF','WLR','SMPF','BB_CONNECT'",
from: tableid, // fusion table name
geometryColumn: 'geometry', // geometry column name
suppressMapTips: true, // optional, whether to show map tips. default false
delay: 100, // milliseconds mouse pause before send a server query. default 300.
tolerance: 8 // tolerance in pixel around mouse. default is 6.
});
addListeners2();
}
function addListeners1()
{
google.maps.event.addListener(layer, 'mouseover', function(fEvent)
{
var row = fEvent.row;
myHtml = '<TABLE width = "600" cellspacing="0" cellpadding="0"><TR>';
myHtml += '<TD><b>REGION</b></TD>';
myHtml += '<TD><b>EXCHANGE</b></TD>';
myHtml += '<TD><b>MPF</b></TD>';
myHtml += '<TD><b>WLR</b></TD>';
myHtml += '<TD><b>SMPF</b></TD>';
myHtml += '<TD><b>BB_CONNECT</b></TD></TR><TR>';
for (var x in row)
{
if (row.hasOwnProperty(x))
{
myHtml += '<td>' + row[x].value +'</td>';
}
}
myHtml += '</TR></TABLE>';
document.getElementById('info').innerHTML = myHtml;
});
}
function addListeners2()
{
google.maps.event.addListener(layer, 'mouseover', function(fEvent)
{
var row = fEvent.row;
myHtml = '<TABLE width = "600" cellspacing="0" cellpadding="0"><TR>';
myHtml += '<TD><b>REGION</b></TD>';
myHtml += '<TD><b>EXCHANGE</b></TD>';
myHtml += '<TD><b>MPF</b></TD>';
myHtml += '<TD><b>WLR</b></TD>';
myHtml += '<TD><b>SMPF</b></TD>';
myHtml += '<TD><b>BB_CONNECT</b></TD></TR><TR>';
for (var x in row)
{
if (row.hasOwnProperty(x))
{
myHtml += '<td>' + row[x].value +'</td>';
}
}
myHtml += '</TR></TABLE>';
document.getElementById('info').innerHTML = myHtml;
});
}
}
I'm not familiar with the Fusion Tips utility library but the documentation shows it does not support a where clause. Which kind of makes sense. A tool tip would be associated with a single point or polygon. You need a where clause, i.e. select exchanges where region = XXX.
I'd try the google.visualization library which would allow you to execute such a query or you could use the Fusion Table JSONP API which would allow the same. There's a visualization example here, quite a bit different, but could be modified to handler what you want to do.
I have found the solution!!!
function loadRegion()
{
if (layer != null)
{
layer.setMap(null);
google.maps.event.clearInstanceListeners(layer);
}
layer = new google.maps.FusionTablesLayer
({
query:
{
select: 'geometry',
from: tableid
},
map: map
})
google.maps.event.addListener(layer, 'click', function(e)
{
if (e && e.row && e.row["REGION"])
{
query4infowindowData(e.row["REGION"].value);
infowindow.setPosition(e.latLng);
}
else
{
alert("no row:"+e.latLng);
}
});
}
function query4infowindowData(term)
{
var queryText = "SELECT 'REGION', 'EXCHANGE', 'MPF', 'WLR', 'BB_CONNECT', 'SMPF' FROM "+tableid+" WHERE 'REGION' = '"+term+"';";
var encodedQuery = encodeURIComponent(queryText);
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + encodedQuery);
query.send(openInfoWindow);
}
function openInfoWindow(response)
{
if (!response)
{
alert('no response');
return;
}
if (response.isError())
{
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
FTresponse = response;
numRows = response.getDataTable().getNumberOfRows();
numCols = response.getDataTable().getNumberOfColumns();
var dataTable = response.getDataTable();
var contents = "REGION: <u><b>"+dataTable.getValue(0,0)+"</b></u><br><table border='1'><tr><th>#</th><th>EXCHANGE</th><th>MPF</th><th>WLR</th><th>BB_CONNECT</th><th>SMPF</th></tr>";
for(i = 0; i < numRows; i++)
{
contents += "<tr><th>"+i+"</th><td>"+dataTable.getValue(i,1)
+"</td><td>"+dataTable.getValue(i,2)
+"</td><td>"+dataTable.getValue(i,3)
+"</td><td>"+dataTable.getValue(i,4)
+"</td><td>"+dataTable.getValue(i,5)
+"</td></tr>";
}
contents += "</table>";
document.getElementById('info').innerHTML = contents;
}