-3

i am calling initialize function on parks tag class then club tag class then map reload again i want to stop map reload and print parks when click on parks class and print clubs when click clubs class.the same functionality works on some other types.

function initialize(lat, lon, typ) {
                var pyrmont = new google.maps.LatLng(lat,lon);
                map = new google.maps.Map(document.getElementById('map'), {
                center: pyrmont,
                zoom: 15
                });
                //var latlng = new google.maps.LatLng(-24.397, 140.644);


                var request = {
                    location: pyrmont,
                    radius: 400,
                    types: [typ]
                };
                infowindow = new google.maps.InfoWindow();
                var service = new google.maps.places.PlacesService(map);
                service.nearbySearch(request, callback);
                var myCity = new google.maps.Circle({
          center: pyrmont,
          radius: 500,
          strokeColor: "#0000FF",
          strokeOpacity: 0.8,
          strokeWeight: 1,
          fillColor: "#0000FF",
          fillOpacity: 0.1,
          editable: true
        });

        myCity.setMap(map);


            }

            function callback(results, status) {
                if (status == google.maps.places.PlacesServiceStatus.OK) {

                    for (var i = 0; i < results.length; i++) {
                    createMarker(results[i]);
                    }
                }
            }

function createMarker(place) {
  var placeLoc = place.geometry.location;
   var marker = new google.maps.Marker({
    map: map,
    position: place.geometry.location,
    icon:'icone/'+typ+'.png',
  });

  google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
  });
}
geocodezip
  • 158,664
  • 13
  • 220
  • 245

1 Answers1

0

You won't want to run your initialize function again, because it will try to create another map.

To find the new set of places, you simply need to change your request array and call the nearbySearch function again. Here is the order of things you need to do when the user changes the 'Type'.

  • Request array is changed to have the new type (request = {......})
  • searchNearby function is called again to pull in the new Places
  • In the callback function, clear the markers from the old 'Type' off of the map

To do all of this, you should make your map a global variable so that you can reference it from any function. Similarly, you should store your Markers in a global array so that you can loop through it to easily remove them when a new type is selected.