1

I want to display multiple locations on a google map at the same time using json.

I am not sure how to do that. I have displayed a map but with only one position

Here is the json:

{
    "post_country": "Vietnam",
    "post_latitude": 10.4452129,
    "post_longitude": 106.4729811
},

{
    "post_country": "Kyrgyzstan",
    "post_latitude": 41.1694718,
    "post_longitude": 75.8098141
},

{
    "post_country": "China",
    "post_latitude": 34.2456501,
    "post_longitude": 108.9877602
},

I have used some values randomly in the below example

Here is my code:

<agm-map [latitude]="latitude" [longitude]="longitude" >

</agm-map>

latitude: number = 51.678418;
longitude: number = 7.809007;
2
  • <agm-map [latitude]="latitude" [longitude]="longitude" > </agm-map> Commented Apr 11, 2018 at 4:16
  • in the google maps library there is markers, add marker, remove marker, and so on, check the docs of the library you are using for this thing Commented Apr 11, 2018 at 6:18

2 Answers 2

2

You can try this, works for me:

HTML:

<agm-map  [latitude]="lat" [longitude]="lng" >        
    <agm-marker  *ngFor = "let post of positions" [latitude]="post.post_latitude" [longitude]="post.post_longitude"></agm-marker>
</agm-map>

.ts:

lat = 6.05246325;
log = 9.01555559;

positions = [{
    "post_country": "Vietnam",
    "post_latitude": 10.4452129,
    "post_longitude": 106.4729811
}, {
    "post_country": "Kyrgyzstan",
    "post_latitude": 41.1694718,
    "post_longitude": 75.8098141
}, {
    "post_country": "China",
    "post_latitude": 34.2456501,
    "post_longitude": 108.9877602
}]
Sign up to request clarification or add additional context in comments.

Comments

0

You can add some <agm-marker></agm-marker> into the <agm-map></agm-map>, according to the official documentation.

<agm-map [latitude]="latitude" [longitude]="longitude">
   <agm-marker [latitude]="lat1" [longitude]="long1"></agm-marker>
   <agm-marker [latitude]="lat2" [longitude]="long2"></agm-marker>
</agm-map>

Just replace the latitude et longitude attributes by values from your json.

See this example.

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.