1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

@types/google.maps: Cannot find name 'google'

Discussão em 'Angular' iniciado por Jeb50, Setembro 27, 2024.

  1. Jeb50

    Jeb50 Guest

    Application just needs zip code input from customers to calculate distances between two points in order to recommend the closest store. No need to display/draw a map. Have a valid Google API Key tested with Postman and a regular Chrome at https://maps.googleapis.com/maps/api/distancematrix/json?. But got CORS using http.get<any>(urlwithparams) from inside application. Found out Google intentionally not allow request from script, have to use its library.

    No problem! After reading many posts and Google's Developer Guide, believe I should use DistanceMatrixService and this is the easy sample to follow https://developers.google.com/maps/...stance-matrix#maps_distance_matrix-typescript

    My component .HTML:

    <script
    src="https://maps.googleapis.com/maps/api/js?key=KeyValue&callback=clickFind&v=weekly"
    defer
    ></script>


    My component .ts:

    clickFind()
    {
    const map = new google.maps.DistanceMatrixService; <<-- Error: TS2663: Cannot find name 'google'
    ....
    }


    Result is Cannot find name 'google'. I have tried all the followings,

    Cannot find name 'google' angular 8

    Google Maps API: No 'Access-Control-Allow-Origin' header is present on the requested resource

    Typescript Error Cannot find name 'google' in ionic2 when using googlemaps javascript API

    @types/googlemaps/index.d.ts' is not a module

    https://www.freakyjolly.com/angular-google-maps-using-agm-core/#more-2316

    https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#request-examples

    https://www.joshmorony.com/getting-started-with-google-maps-in-ionic-2/

    eventually came back to the same


    Error: TS2663: Cannot find name 'google'
    ​

    Summary

    1. @types/googlemaps has been deprecated, if you install it will be told switching over to @types/google.maps even though it still placed @types/googlemaps in package.json, so I ran npm i @types/google.maps --save-dev instead.
    2. The installed version is "@types/google.maps": "^3.51.0"
    3. Many posts above are using early Angular versions up to 9, or axios while mine is Angular v14
    4. @agm/core should not be needed.
    5. Some solutions above build ok but fail at run time for the error.

    Continue reading...

Compartilhe esta Página