Google API Address Components

前端 未结 3 1615
借酒劲吻你
借酒劲吻你 2020-12-12 07:02

I am attempting to obtain the address components using the Google Maps API however am unable to properly parse results. My code is as follows:

    // Ajax C         


        
3条回答
  •  温柔的废话
    2020-12-12 07:23

    a little late but this is that i have

    calle === street

    nro === street_number

    extraerCalle(resultado: IResult): string | undefined {
        const route = resultado.address_components.find(ac => !!ac.types.find(type => type === 'route'));
        return route && route.long_name;
      }
    
      extraerNro(resultado: IResult): string | undefined {
        const streetNumber = resultado.address_components.find(ac => !!ac.types.find(type => type === 'street_number'));
        return streetNumber && streetNumber.long_name;
      }
    
      extraerCalleNro(resultado: IResult): string {
        const calle = this.extraerCalle(resultado);
        const nro = this.extraerNro(resultado);
        return (calle || '') + (calle && nro ? ` ${nro}` : '');
      }
    

提交回复
热议问题