...

View Full Version : Limited number of results (Google maps API)



shlagish
07-16-2009, 02:58 PM
Hello,

I'm trying to use google maps for the web application I'm developping. The idea is I have a database with all the universities with whom we exchange. I know where each university is (city). What I want to do is show all the cities on a google map (as markers)
Here is the code I am using:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
<title>Trouver une université d'accueil</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAyddaCMLynA_00r_M38R_TRQj6Z6VgkTRnHSQUsYiDp309FxmwxR9eUK5cyGOtQg8LSks6PIr0kmeUw" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map;
var villes = new Array
(
"Logroño",
"Albi",
"Albuquerque, NM",
"Alès",
"Amiens",
"Bath",
"Berlin",
"Besançon",
"Bruxelles",
"Bucarest",
"Buenos Aires",
"Cachan",
"Campinas-SP",
"Casablanca",
"Chambéry",
"Champs-sur-Marne ",
"Chapel Hill",
"Compiègne",
"Cordoba",
"Douai",
"Edmonton",
"Gand",
"Grenoble",
"Guadalajara",
"Göteborg",
"Haifa",
"Hatfield",
"Hong Kong",
"Illkirch",
"Insurgentes Mixcoac",
"Lausanne",
"Levallois-Perret",
"Lille",
"Linköpings",
"Louvain",
"Lulea",
"Lund",
"Lyon",
"Madrid",
"Marseille",
"Medellin",
"Melbourne",
"Metz",
"Mexico",
"Milan",
"Munich",
"Nancy",
"Nantes",
"Paris",
"Paris (Palaiseau)",
"Poitier",
"Prague",
"Puebla",
"Reykjavik",
"Rio de Janeiro",
"Rueil-Malmaison",
"Saint-Étienne",
"Saint-Étienne-du-Rouvray",
"San Diego, CA",
"Sceaux",
"Strasbourg",
"Stuttgart",
"Talence",
"Tampere",
"Tobata",
"Tokyo",
"Toulouse",
"Turin",
"Uppsala",
"Valencia",
"Vaulx en Velin",
"Villeurbanne",
"Zurich"
/* 73 cities */
);


// On page load, call this function
function load()
{
var geocoder;
// Create new map object
map = new GMap2(document.getElementById("map"));

// Create new geocoding object
geocoder = new GClientGeocoder();

// Retrieve location information, pass it to addToMap()
var villesLength = villes.length;
for(var i = 0; i < villesLength; ++i)
{
geocoder.getLocations(villes[i], addToMap);
}
//Center the map
/*Add controls: Zoom controls, Type Controls,
Add event listeners: Scroll event*/
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(40, 0), 0);
}

// This function adds the point to the map
function addToMap(response)
{
if(!response || response.Status.code != 200)
{
alert(villes[i]);
}
// Retrieve the object
place = response.Placemark[0];

// Retrieve the latitude and longitude
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);

// Create a marker
var marker = new GMarker(point);
GEvent.addListener(marker, "click",
function()
{
marker.openInfoWindowHtml(response.Placemark[0].address);
}
);
map.addOverlay(marker);
}
window.onload = load;
window.onunload = GUnload();
//]]>
</script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px;"></div>
</body>
</html>

The code works well, it finds the cities and places a marker at the appropriate place. BUT, only 18 out of the 73 cities are shown. If I take away some cities from the list, the others are found. All the cities can be found this way, but only up to 18 appear at a time.

Does anyone know how to avoid having this limit?

Thank you very much.

fside
07-16-2009, 10:19 PM
If there's not a problem with the #19th entry, then it could be you hit a 'geocoding' limit that I believe Google said they would repair in the near future.

shlagish
07-17-2009, 02:12 PM
Well it turns out that I was making too many requests in a too short time period of time. What I'm doing now is testing whether the "too many requests error" occurs and, if so, try again.

Works like a charm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum