Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Limited number of results (Google maps API)

    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:
    Code:
    <!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.
    Shawn

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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
    Shawn


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •