Google maps API error

Hi
I have this code:

    let latitude: number[] =
    [
       51.779849,
       51.765845
    ];
    let longitude: number[] =
    [
       19.446626,
       19.457092
    ];

    for( var i = 0; i < latitude.length; i++ ) {
       this.map.addMarker({
       'position': new google.maps.LatLng(latitude[i], longitude[i]),
       'title': "Title"
     });
    }

And I get this error:
Error:(75, 26) TS2345: Argument of type '{ 'position': LatLng; 'title': string; }' is not assignable to parameter of type 'GoogleMapsMarkerOptions'. Types of property 'position' are incompatible. Type 'LatLng' is not assignable to type 'GoogleMapsLatLng'. Types of property 'lat' are incompatible. Type '() => number' is not assignable to type 'number'

Which is weird, because the same type declaration is in documentation in Google Maps API.
Any advices?

I would try changing

    for( var i = 0; i < latitude.length; i++ ) {
       this.map.addMarker({
       'position': new google.maps.LatLng(latitude[i], longitude[i]),
       'title': "Title"
     });

to this:

    for( var i = 0; i < latitude.length; i++ ) {
       this.map.addMarker({
       position: new GoogleMapsLatLng(latitude[i], longitude[i]),
       title: "Title"
     });

The main issue is that these are typescript and ionic-native errors, so while they may be the same type declarations in Google’s documentation, they’re not what the plugin/typescript is expecting.

Thanks a lot!!!

Helloooo,

I know it has been a while but I kinda had the same issue and dont know how to fix it. I have a React Typescript app and i am getting this error:

Argument of type ‘LatLng | undefined’ is not assignable to parameter of type ‘LatLngLiteral | LatLng’.
Type ‘undefined’ is not assignable to type ‘LatLngLiteral | LatLng’.ts(2345)

const onPlaceChanged = () => {
const place = autocompleteRef.current?.getPlace();
const bounds = new window.google.maps.LatLngBounds();
if (place && place.geometry) {
if (place.geometry.viewport) {
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
mapRef.current?.fitBounds(bounds);
}
};