angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Is their a possibility to display multiple pins within a defined radius with Angular Google Maps?

Open amritofficial opened this issue 8 years ago • 1 comments

Issue description I have been trying to display multiple pins using a ngFor loop in a defined radius of a location but it doesnt seem to work. It wont even take the string interpolation values even if I have it without the braces.

Steps to reproduce and a minimal demo of the problem

_Use https://plnkr.co or similar -- try this template as a starting point: http://plnkr.co/edit/YX7W20?p=preview

What steps should we try in your demo to see the problem?

Current behavior String Interpolation from an Array of Map Json data doesn't work and cannot display multiple pins around the defined location.

Expected/desired behavior Multiple Pins around the defined location as per the received JSON data using ngFor Loop

angular2 & angular-google-maps version Angular/Cli: 1.5.0 Angular-google-maps: Latest fresh install from NPM

Other information

amritofficial avatar Dec 18 '17 20:12 amritofficial

Make sure you provide to agm-marker component your coordinates as numbers, not as string. Here is small example how I made similar task:

Some logic in my controller

import * as LatLon from "mt-latlon"; // Good library for true geo calculations https://www.npmjs.com/package/mt-latlon

public mapPoints = [];
public radius: number;
public currentLocation: {
    latitude: 47.024629,
    longitude: 28.832407
  };

ngOnInit(){
    this.generateMapPoints(this.currentLocation, this.radius, 50);
}

 public randomGeo(center, radius){
    let angle = Math.random()*Math.PI*2*100;
    let originalPoint = new LatLon(center.latitude, center.longitude);
    let destinationPoint = originalPoint.destinationPoint(angle, radius);
    let res = {
      'latitude': +destinationPoint.lat().toFixed(5),
      'longitude': +destinationPoint.lon().toFixed(5),
      'radius': +radius,
      'angle': +angle,
    };
    return res;
  }

  public generateMapPoints(centerpoint, distance, amount) {
    this.mapPoints = [];
    for (let i=0; i<amount; i++) {
      this.mapPoints.push(this.randomGeo(centerpoint, distance));
    }
  }

And simple ngFor in template:

<agm-map [latitude]="currentLocation.latitude" [longitude]="currentLocation.longitude">
    <agm-marker *ngFor="let point of mapPoints;" [latitude]="point.latitude" [longitude]="point.longitude">
        <agm-info-window>{{point | json}}</agm-info-window>
    </agm-marker>
</agm-map>

AndrewMAGIK avatar Jan 23 '18 22:01 AndrewMAGIK