Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49246

Google Map issue

$
0
0

@flycoders_sourav wrote:

The marker that I click on. this marker not open Info window but a another markers info window is open

below my code

public loadMap(){

    this.geolocation.getCurrentPosition().then((position) => {

      this.latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);



      this.mapOptions = {
        center: this.latLng,
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      this.map = new google.maps.Map(this.mapElement.nativeElement, this.mapOptions);
       this.nearbyPlace();
       this.addMarkercurrentuserlocation();
    }, (err) => {
      alert('err '+err);
    });

  }
  /*-----------------Find Nearby Place------------------------*/

public nearbyPlace(){
    this.markers = [];
    let service = new google.maps.places.PlacesService(this.map);
    service.nearbySearch({
              location: this.latLng,
              radius: 300,
              types: ['bank']
            }, (results, status) => {
                this.callback(results, status);
            });
  }

public callback(results, status) {
    if (status === google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {
        this.createMarker(results[i]);
      }
    }
  }
public createMarker(place){
    var placeLoc = place;
    console.log('placeLoc',placeLoc)
    this.markers = new google.maps.Marker({
        map: this.map,
        position: place.geometry.location,
        icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
        //title: place.features[1].name

    });

    let infowindow = new google.maps.InfoWindow();

    google.maps.event.addListener(this.markers, 'click', () => {
      this.ngZone.run(() => {
        infowindow.setContent(place.name[1]);
        infowindow.open(this.map, this.markers);
      });
    });
  }
public addMarkercurrentuserlocation(){

	  let marker = new google.maps.Marker({
	    map: this.map,
	    animation: google.maps.Animation.DROP,
	    position: this.map.getCenter()
	  });

	  let content = "<h4>Me</h4>";

	  this.addInfoWindow(marker, content);

	}
	  addInfoWindow(marker, content){

    let infoWindow = new google.maps.InfoWindow({
      content: content
    });

    google.maps.event.addListener(marker, 'click', () => {
      infoWindow.open(this.map, marker);
    });

  }

how can i fix that
Please help me
Sorry for poor English
Thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49246

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>