custom property with google marker in type script
Asked Answered
B

1

6

I'm using type script and getting below error when trying to set custom property with Google marker. Can anyone please advice how to set custom property with Google Map Marker?

Argument of type '{ position: LatLng; map: any; icon: string; zIndex: number; se10: any; }' is not assignable to parameter of type 'MarkerOptions'. Object literal may only specify known properties, and 'se10' does not exist in type 'MarkerOptions'.

The following Javascript code is working well.

var marker = new google.maps.Marker({
            position: new google.maps.LatLng(Number(merchant[lat]), Number(merchant[lng])),
            map: map,
            icon: icon,
            zIndex: zIndex ,
            se10: merchant.se
        });
Bite answered 21/2, 2016 at 21:10 Comment(0)
B
8

Got it . below is type script code -

var marker = new google.maps.Marker({
                position: new google.maps.LatLng(Number(merchant[lat]), Number(merchant[lng])),
                map: map,
                icon: icon,
                zIndex: zIndex ,
            });
            marker.set("se10",merchant.se);
Bite answered 21/2, 2016 at 21:14 Comment(3)
Wouldn't you get a new error that Property 'se10' does not exist on type Marker? Or did you not define "marker" as type google.maps.Marker?Bruni
My IDE offered me to use string literal to avoid error - marker[`se10`]Vair
I lost quite a lot of time with this problem today. Thanks to your @Raj.Obit

© 2022 - 2024 — McMap. All rights reserved.