0

During the execution of my script with a line 169 I turn to line 182.

enter image description here

What could be the problem ?

1 Answer 1

1

I am using this function initMap in onload function it works for me i hope it will helpful for you

function initMap() {
            map = new google.maps.Map(document.getElementById('mapSection'), {
                center: { lat: 13.0480787, lng: 79.9288088 },
                zoom: 10, 
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                zoomControl: true,
                zoomControlOptions: {
                    position: google.maps.ControlPosition.LEFT_CENTER
                },

            });

         // Create the search box and link it to the UI element.
  var input = document.getElementById('pac-input');
  var searchBox = new google.maps.places.SearchBox(input);
  map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

  // Bias the SearchBox results towards current map's viewport.
  map.addListener('bounds_changed', function() {
    searchBox.setBounds(map.getBounds());
    var bounds = map.getBounds();
  });

  var markers = [];
  var geocoder = new google.maps.Geocoder();

  searchBox.addListener('places_changed', function() {
    var places = searchBox.getPlaces();

    if (places.length == 0) {
      return;
    }
    geocodeAddress(geocoder, map);    
    // Clear out the old markers.
      markers.forEach(function(marker) {
      marker.setMap(null);
    });
    markers = [];  
    // For each place, get the icon, name and location.
    var bounds = new google.maps.LatLngBounds();
    map.fitBounds(bounds);
  });
  // [END region_getplaces]


  function geocodeAddress(geocoder, resultsMap) {

              var address = document.getElementById('pac-input').value;
              geocoder.geocode({'address': address}, function(results, status) {
                if (status === google.maps.GeocoderStatus.OK) {

                } else {
                  alert('Geocode was not successful for the following reason: ' + status);
                }
              });
            }
}

and if you want Marker on map use this function

function create_Marker(lat, lan, drivername, indx) {

     var MARKER = new google.maps.Marker({
        position : new google.maps.LatLng(lat, lan),
        map : MAP,
        icon : "images/car.png",
        title : drivername,
        animation : google.maps.Animation.DROP
    });
    MARKER_List.push(MARKER);
    google.maps.event.addListener(MARKER, 'click', (function(marker, indx) {
        return function() {
            infowindow.setContent("<div class='content' style='max-height:300px; font-size:12px;';'>" + drivername
                    + "</div>");
            infowindow.open(MAP, marker);
        }
    })(MARKER, indx));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.