Guest User

Google Maps API

a guest
Jan 7th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var map,
  2.                 bounds,
  3.                 geocoder,
  4.                 center;
  5.  
  6.            
  7.             function addMarkerToMap(location, address){
  8.             //var image = "assets/img/set_image.png"; // Replace set_image.png with image path
  9.                
  10.                 var marker = new google.maps.Marker({
  11.                         map: map,
  12.                         position: location,
  13.                         //icon: image
  14.                 });
  15.                 bounds.extend(location);
  16.                 map.fitBounds(bounds);
  17.                 var infoWindow = new google.maps.InfoWindow({
  18.                     content: address
  19.                 });
  20.                 google.maps.event.addListener(marker, 'click', function() {
  21.                     infoWindow.open(map, marker);
  22.                 });
  23.             }
  24.            
  25.             function initialize() {
  26.               var mapOptions = {
  27.                 scrollwheel: false,
  28.                 mapTypeControl: false,
  29.                 streetViewControl: false,
  30.                 zoom: 10,
  31.                 center: new google.maps.LatLng(37.09024, -95.712891),
  32.                 mapTypeId: google.maps.MapTypeId.ROADMAP
  33.               };
  34.               map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  35.                 geocoder = new google.maps.Geocoder();
  36.                 bounds = new google.maps.LatLngBounds();
  37.             }
  38.  
  39.             initialize();
  40.            
  41.             $('address', parent.window.document).each(function() {
  42.                
  43.                 var $address = $(this);
  44.                 // TRYED WRAPPING setTimeOut FUNCTION HERE BUT NO LUCK
  45.                 geocoder.geocode({ address: $address.html() }, function(
  46.                     results,
  47.                     status
  48.                     )  {
  49.                     if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(
  50.                          results[0].geometry.location, $address.html());
  51.                 }); // ENDED FUNCTION HERE }, 2000); BUT NO LUCK
  52.                
  53.                 console.log($address.length);
  54.             });
  55.  
  56.             google.maps.event.addDomListener(map, 'idle', function() {
  57.             center = map.getCenter();
  58.         });
  59.  
  60.         $(window).resize(function() {
  61.             map.setCenter(center);
  62.            
  63.         });
Add Comment
Please, Sign In to add comment