0

On a click of a button I am setting the latitude and longitude in the map-marker but lightning-map is updating/refreshing. Here is the code: HTML:

<template>
<lightning-button label='Click' onclick={handleClick}></lightning-button>
    <lightning-map
        map-markers={mapMarkers}
    >
  </lightning-map>
</template>

JS:

import { LightningElement, track } from 'lwc';

export default class Lwc_map extends LightningElement {

   
    @track mapMarkers=[];

    handleClick(event){
        this.mapMarkers={
            location: {
                Latitude: '28.535517',
                Longitude: '77.39103',
                
            }
        
        }
        window.console.log('Set'+ JSON.stringify(this.mapMarkers));
    }
}

Pls,suggest me method how i can update lightning-map on a click in lwc.

1 Answer 1

1

mapMarkers is an array so you should put the content like this

 this.mapMarkers = [...this.mapMarkers, {
            location: {
                Latitude: '28.535517',
                Longitude: '77.39103',
                
            }
        
        }];
       
3
  • Thanks User6670.
    – jegoxab
    Commented Jul 22, 2020 at 12:02
  • I am using your provided way in a location showing app but its not updating the map.
    – jegoxab
    Commented Jul 22, 2020 at 12:35
  • @jegoxab it works for me may be you can put your whole code
    – User6670
    Commented Jul 22, 2020 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .