www.webdeveloper.com
Results 1 to 3 of 3

Thread: Google Maps Geocoder

  1. #1
    Join Date
    Mar 2012
    Posts
    13

    Google Maps Geocoder

    Hello,

    I am have added a google map to my website successfully, the only problem is that I have 16 different locations and only 11 of them are showing up. I have done some research into this and Google has limited the number of request on a load, which in this case would be 11. I found a few places saying that if you put a specific time limit on the request you can load more locations. One example is here. https://groups.google.com/forum/?fro...v3/FKvDIa0P1bw I was just wondering if anyone would know how to do that same thing but make it function with my code. My code is pasted below. Any help in the right direction would be greatly appreciated.

    Code:
    <script type="text/javascript" src="http://tropitan.biz/wp-content/themes/tropitan/js/jquery.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDbsdaxW8es67YUELxpATte1jBbABTVZQQ&sensor=false"></script>
    <script type="text/javascript">
    $("#bigmap").prepend('<div id="map_canvas"></div>');
    $(".static_map").remove();
    var bounds;
    var geocoder;
    function initialize() {
    					var mapOptions = {
    						center: new google.maps.LatLng(42.970625, -83.777093),
    						zoom: 8,
    						mapTypeId: google.maps.MapTypeId.ROADMAP
    					};
    					map = new google.maps.Map(document.getElementById("map_canvas"),
    						mapOptions);
    					geocoder = new google.maps.Geocoder();
    					bounds = new google.maps.LatLngBounds();
    				}
    				function addMarkerToMap(location){
    					var marker = new google.maps.Marker({map: map, position: location});
    					bounds.extend(location);
    					map.fitBounds(bounds);
    				}
    
    				initialize();
    
                                    
    
    				$("address").each(function(){
    					var $address = $(this);
    					geocoder.geocode({address: $address.text()}, function(results, status){
    						if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(results[0].geometry.location);
    					});
    				});
    
    				
    
    </script>

  2. #2
    Join Date
    Nov 2010
    Posts
    1,083
    where do your 16 locations come from? are they decided by you or the user? Because if you know them in advance, to me it seems the best advice is from the forum thread that you posted:

    The general advice is not to geocode addresses everytime your page
    loads. Geocode them once, offline, then use the resulting coordinates
    to display the markers.

    Geocoding the addresses every time wastes google's resources, so they
    have implemented rate limits and quotas. You should only geocode
    addresses you don't know in advance (like user input) on the fly.

  3. #3
    Join Date
    Oct 2011
    Location
    Australia
    Posts
    22
    Quote Originally Posted by jcbrmn06 View Post
    Hello,

    I am have added a google map to my website successfully, the only problem is that I have 16 different locations and only 11 of them are showing up. I have done some research into this and Google has limited the number of request on a load, which in this case would be 11. I found a few places saying that if you put a specific time limit on the request you can load more locations. One example is here. https://groups.google.com/forum/?fro...v3/FKvDIa0P1bw I was just wondering if anyone would know how to do that same thing but make it function with my code. My code is pasted below. Any help in the right direction would be greatly appreciated.

    Code:
    <script type="text/javascript" src="http://tropitan.biz/wp-content/themes/tropitan/js/jquery.js"></script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDbsdaxW8es67YUELxpATte1jBbABTVZQQ&sensor=false"></script>
    <script type="text/javascript">
    $("#bigmap").prepend('<div id="map_canvas"></div>');
    $(".static_map").remove();
    var bounds;
    var geocoder;
    function initialize() {
    					var mapOptions = {
    						center: new google.maps.LatLng(42.970625, -83.777093),
    						zoom: 8,
    						mapTypeId: google.maps.MapTypeId.ROADMAP
    					};
    					map = new google.maps.Map(document.getElementById("map_canvas"),
    						mapOptions);
    					geocoder = new google.maps.Geocoder();
    					bounds = new google.maps.LatLngBounds();
    				}
    				function addMarkerToMap(location){
    					var marker = new google.maps.Marker({map: map, position: location});
    					bounds.extend(location);
    					map.fitBounds(bounds);
    				}
    
    				initialize();
    
                                    
    
    				$("address").each(function(){
    					var $address = $(this);
    					geocoder.geocode({address: $address.text()}, function(results, status){
    						if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(results[0].geometry.location);
    					});
    				});
    
    				
    
    </script>
    Thanks to share this info with us.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles