var classBounds = new google.maps.LatLngBounds();
var query = "";
query = "SELECT 'ROAD_NUMBER', 'geometry' FROM [TABLE_REFERENCE_ID] WHERE 'ROAD_NUMBER' CONTAINS IGNORING CASE '" + searchString + "' AND 'LINK_NUMBER' CONTAINS '" +searchStringLinkNo + "'";
var encodedQuery = encodeURIComponent(query);
// Create URL
var url = ['https://www.googleapis.com/fusiontables/v1/query'];
url.push('?sql=' + encodedQuery);
url.push('&key=[API_KEY]');
url.push('&callback=?');
// Perform JSONP request with jQuery
$.ajax({
url: url.join(''),
dataType: 'jsonp',
success: function (data){
var rows = data['rows'];
if(rows){
var classRoadGeo1 = rows[0][1].geometry.coordinates;
var classRoadGeo2 = rows[rows.length - 1][1].geometry.coordinates;
var classRoadGeoStart = classRoadGeo1[0];
var classRoadGeoEnd = classRoadGeo2[classRoadGeo2.length - 1];
var startHolder = classRoadGeoStart.toString();
var endHolder = classRoadGeoEnd.toString();
var bound1 = startHolder.split(",");
var bound2 = endHolder.split(",");
var coordinate1 = new google.maps.LatLng(bound1[1], bound1[0]);
var coordinate2 = new google.maps.LatLng(bound2[1], bound2[0]);
alert(bound1);
alert(bound2);
classBounds.extend(coordinate1);
classBounds.extend(coordinate2);
}
else{
alert("Unable to find any stations for the selected criteria.");
}
}
});
map.fitBounds(classBounds);
}
The code above retrieves geometry information from a fusion table, converts it into string, and creates LatLng objects. However, when using fitBounds, it incorrectly centers on Papua New Guinea instead of Kiama in Sydney, Australia. No errors are displayed. Any suggestions on what may be causing this?