Google Maps Limit


My database stores the latitude and longitude of every customer.  Those are then used to populate a Google Map with the following code:

      //--- Add Map Marker -------------------------------------------------
      var marker = new google.maps.Marker({
          position: new google.maps.LatLng(lat,lng),
          map: map,
          icon: pinImageBlue ,
          title: name,
          url: url

Open in new window

I'm aware that Google puts a limit on the number of Geocoding calls one requests.

Does my code count against that daily Google Maps limit?  

If so, then is it possible to store the "position" variable in my MySQL database?  

Basically, I don't want to bump up against Google's limits when this thing goes into production.

Thank You!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Loganathan NatarajanLAMP DeveloperCommented:
then is it possible to store the "position" variable in my MySQL database?  

You cannot block to count the Google API limit.  Go through more details here to go paid services,
Tom BeckCommented:
"Does my code count against that daily Google Maps limit?"

Cannot tell anything from that piece of code. It's not making any call to Google's geocoder. Is it part of a loop? How many calls do you need to make to the geocoder? You cannot make rapid fire calls, you have to use timers to meter them in slowly unless you pay. This can delay the rendering of the map for several seconds.

The geocoder service converts addresses and place names to longitude/latitude pairs so they can be plotted to a map. If you are storing latitude/longitude values in a database then why the need for a geocoder? Just put a marker at each location. You can put as many markers on a Google map as you want, no limit. The limit is on geocoding.

Here's a stand alone example of a Google map that places 40,000 markers on the map. Zoom out and drag it around. I have zoom limited to level 10 because the map gets completely covered with markers if you zoom out further. It loads fast because it only renders the markers that are currently in the map viewport rather than all 40,000. Google's geocoder service is not involved in any way.
<!DOCTYPE html>
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps - 40,000 markers</title> 
   <script src="" 
   <div id="map" style="width: 900px; height: 500px;"></div> 
   <span id="results"></span>

   <script type="text/javascript"> 
   /*The following creates 40411 latitude/longitude pairs. For testing purposes only*/
   /*This represents coordinate information retrieved from a database, xml file, web service, etc.*/
   /*Actual coordinate retrieval would best be done server side through an ajax or json call*/
var lngIncrement = (116.718750 - 108.017578)/160;
var latIncrement = (33.284620 - 31.578535)/250;
var latlng = [], latPos = latIncrement, lngPos = lngIncrement;
for (var i = 0; i<251; i++){
	for (var j = 0; j<161; j++) {
		latlng.push({lat: ((31.578535 + latPos) + ((31.578535 + latPos + latIncrement) - (31.578535 + latPos))*Math.random()), lng: (((108.017578 + lngPos) + ((108.017578 + lngPos + lngIncrement) - (108.017578 + lngPos))*Math.random())*-1)});
		lngPos += lngIncrement;
	latPos += latIncrement;
	lngPos = lngIncrement;
/*end latitude/longitude pairs array for testing purposes*/

	  var viewportPoints = [];
	  var markers = [];
	  // create a map centered on a random point in the middle of the United States
      var myOptions = {
		zoom: 14,
		scrollwheel: false, 
		center:  new google.maps.LatLng(31.8515086, -110.192871),
	  	mapTypeId: google.maps.MapTypeId.ROADMAP
      var map = new google.maps.Map(document.getElementById("map"), myOptions);
	  // load markers that fall inside viewport when map is idle after load and drag
	  google.maps.event.addListener(map, 'idle', function(){    
	  // Limit the zoom level. This is very important! Otherwise, too many markers in the viewport.
      google.maps.event.addListener(map, 'zoom_changed', function() {
         if (map.getZoom() < 10) map.setZoom(10);		      
	  // clear off all markers
	  google.maps.Map.prototype.clearMarkers = function() {
         for(var i=0; i < markers.length; i++){
		 // reset markers and viewportPoints arrays to empty
         markers.length = 0;
		 viewportPoints.length = 0;

function loadMapFromCurrentBounds() {	

    var bounds = map.getBounds();

    // The bounding rectangle points
    var swPoint = bounds.getSouthWest();
    var nePoint = bounds.getNorthEast();

    // Each individual corner coordinate
    var swLat =;
    var swLng = swPoint.lng();
    var neLat =;
    var neLng = nePoint.lng();
	var latMarkers = [];
	//find latitudes in latlng array that fall into the viewport
	//this is best done server side where the 40,000 points are stored
	for (var i = 0; i < latlng.length; i++) {
		if (latlng[i].lat < neLat && latlng[i].lat > swLat) {
	//find longitudes in latMarkers array that fall into viewport
	//this is best done server side where the 40,000 points are stored
	for (var j = 0; j < latMarkers.length; j++) {
		if (latMarkers[j].lng < neLng && latMarkers[j].lng > swLng) {
	// create the markers that fall inside the viewport
	// best if the marker positions are retrieved as an array or json object from the server
	for (var k = 0; k < viewportPoints.length; k++){
		var point = new google.maps.LatLng(viewportPoints[k].lat, viewportPoints[k].lng);
		var marker = new google.maps.Marker({
            map: map,
            position: point
		// add a click event listener to each marker. This can bring up an info window or whatever.
		// As is, this just clears the marker when it's clicked.
		google.maps.event.addListener(marker, 'click', function(event) {
    document.getElementById("results").innerHTML = markers.length + " markers appear in this viewport";

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
short answer is: no it doesn't
IF you supplied an address instead (i.e. '123 test street, la, ca') then you would need Google's geocoder to get the latLng for you and then THAT would count against your limit.

and of course I'm only referring the piece of code you are show in your post

good luck
SqueezeOJAuthor Commented:
Thanks for your help!

I geocode the street addresses when someone joins the list in another form.  That will never reach the daily limit.  Then when I map it, I use the previously geocoded latitudes & longitudes, so no need to geocode here.  I just wanted to make sure that the LatLng doesn't count against it.
happy mapping ...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Google Apps

From novice to tech pro — start learning today.