Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var map,
- bounds,
- geocoder,
- center;
- function addMarkerToMap(location, address){
- //var image = "assets/img/set_image.png"; // Replace set_image.png with image path
- var marker = new google.maps.Marker({
- map: map,
- position: location,
- //icon: image
- });
- bounds.extend(location);
- map.fitBounds(bounds);
- var infoWindow = new google.maps.InfoWindow({
- content: address
- });
- google.maps.event.addListener(marker, 'click', function() {
- infoWindow.open(map, marker);
- });
- }
- function initialize() {
- var mapOptions = {
- scrollwheel: false,
- mapTypeControl: false,
- streetViewControl: false,
- zoom: 10,
- center: new google.maps.LatLng(37.09024, -95.712891),
- 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();
- }
- initialize();
- $('address', parent.window.document).each(function() {
- var $address = $(this);
- // TRYED WRAPPING setTimeOut FUNCTION HERE BUT NO LUCK
- geocoder.geocode({ address: $address.html() }, function(
- results,
- status
- ) {
- if(status == google.maps.GeocoderStatus.OK) addMarkerToMap(
- results[0].geometry.location, $address.html());
- }); // ENDED FUNCTION HERE }, 2000); BUT NO LUCK
- console.log($address.length);
- });
- google.maps.event.addDomListener(map, 'idle', function() {
- center = map.getCenter();
- });
- $(window).resize(function() {
- map.setCenter(center);
- });
Add Comment
Please, Sign In to add comment