@angular-material-extensions/google-maps-autocomplete

中文文档
16.4.0发布于 2024/09/21MITTypeScriptES Module近 30 天下载 9617

用角和材料设计构建的google-maps自动完成输入组件和指令

中文使用文档
文档目录24 节
  1. 由开发者建并供开发者使用 : 心脏 :
  2. 目录
  3. 演示
  4. 依赖关系
  5. 安装
  6. 1. 通过 纳克后加 . (建议)
  7. 2. 通过 无 . (备选案文)
  8. 要求(类依赖):
  9. 所需额外经费
  10. 使用量
  11. 作为指令
  12. 作为组件
  13. mat-google-maps-auto-complete
  14. API - 更多信息请访问官方文档 地图 JavaScript API
  15. matGoogleMapsAutocomplete
  16. mat-google-maps-autocomplete
  17. mat-search-google-maps-autocomplete
  18. 文档
  19. 本地运行 Demo 应用程序
  20. 发展
  21. 其他角图书馆
  22. 支助
  23. 谁在使用ngx -mailto? 伟大的应用程序?
  24. 许可证

angular-material-extensions's logo

@angular-material-extensions/google-maps-autocomplete - 用angular材料设计建造的google-maps自动完成输入组件

npm version npm demo Join the chat at https://gitter.im/angular-material-extensions/Lobby Coverage Status Build Status CircleCI branch Greenkeeper Badge license Awesome

@angular-material-extensions/google-maps-autocomplete

@angular-material-extensions/google-maps-autocomplete

Please use lib v8 only with angular v15

由开发者建并供开发者使用 : 心脏 :

你有什么问题或建议吗? 请不要犹豫联系我们! 或者,提供 PR QQ 打开适当的 问题 这里

如果你喜欢这个项目,请支持 角-材料-扩展 由主演: 明星: 分享它 : 高音:

目录

演示

在行动中查看所有指令和组成部分 时间 https://angular-material-extension.github.io/google-maps-autocomplete (原始内容存档于2018-09-26)

依赖关系

  • 角质 (单位:千美元)需求 最新动画

选项

npm i -D @types/googlemaps 

安装

如果角材料设计没有设置, 就 运行 ng add @angular/material 学习更多

现在通过 angular schematics 万事俱备

ng add @angular-material-extensions/google-maps-autocomplete

2. 通过 无. (备选案文)

现在安装 @angular-material-extensions/google-maps-autocomplete 通过:

npm install --save @angular-material-extensions/google-maps-autocomplete

要求(类依赖):

请考虑安装以下软件包

ng add @angular/material  

所需额外经费


安装后需要导入主模块 :

import {MatGoogleMapsAutocompleteModule} from '@angular-material-extensions/google-maps-autocomplete';

剩下的唯一部分是在您的应用程序模块中列出导入的模块. 准确的方法是略微的 不同的根(顶级)模块,您最终应当使用类似于(顶级)的代码 通知 MatGoogleMapsAutocompleteModule.forRoot():

import {MatGoogleMapsAutocompleteModule} from '@angular-material-extensions/google-maps-autocomplete';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [
    MatGoogleMapsAutocompleteModule.forRoot('YOUR_GOOGLE_MAPS_API_KEY'), ...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

应用程序中的其他模块可以简单地导入 MatGoogleMapsAutocompleteModule数字 :

import {MatGoogleMapsAutocompleteModule} from '@angular-material-extensions/google-maps-autocomplete';

@NgModule({
  declarations: [OtherComponent, ...],
  imports: [
    MatGoogleMapsAutocompleteModule, ...],
})
export class OtherModule {
}

使用量

作为指令

添加 matGoogleMapsAutocomplete 到您的目标 html 输入元素, 使 google 地图自动完成 api 作为特性


<mat-form-field>
  <mat-label>Address << using the directive >></mat-label>
  <input matInput
         matGoogleMapsAutocomplete
         [country]="de"
         (onAutocompleteSelected)="onAutocompleteSelected($event)"
         (onLocationSelected)="onLocationSelected($event)">
</mat-form-field>

作为组件

或换用 mat-google-maps-auto-complete,UI包装器

添加 mat-google-maps-auto-complete 模板中的元素

mat-google-maps-auto-complete


<mat-google-maps-autocomplete [appearance]="appearance.OUTLINE"
                              (onAutocompleteSelected)="onAutocompleteSelected($event)"
                              (onLocationSelected)="onLocationSelected($event)">
</mat-google-maps-autocomplete>

一个定制的 mat-google-maps-autocomplete


<mat-google-maps-autocomplete country="us"
                              type="address"
                              (onAutocompleteSelected)="onAutocompleteSelected($event)"
                              (onLocationSelected)="onLocationSelected($event)">
</mat-google-maps-autocomplete>

结合 mat-google-maps-autocomplete 带有谷歌映射实例


<div class="container" fxLayout="column" fxLayoutAlign="center">

  <div fxFlex fxFlexAlign="center"
       class="autocomplete-container"
       [ngStyle.xs]="{'min-width.%': 100}"
       [ngStyle.sm]="{'width.%': 70}">
    <mat-google-maps-autocomplete (onAutocompleteSelected)="onAutocompleteSelected($event)"
                                  (onLocationSelected)="onLocationSelected($event)"
                                  (onGermanAddressMapped)="onGermanAddressMapped($event)">
    </mat-google-maps-autocomplete>
  </div>

</div>

在组件中,代码将类似于 -- >

import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {Location, Appearance, GermanAddress} from '@angular-material-extensions/google-maps-autocomplete';
import {} from '@types/googlemaps';
import PlaceResult = google.maps.places.PlaceResult;

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class HomeComponent implements OnInit {

  public appearance = Appearance;
  public zoom: number;
  public latitude: number;
  public longitude: number;
  public selectedAddress: PlaceResult;

  constructor(private titleService: Title) {
  }

  ngOnInit() {
    this.titleService.setTitle('Home | @angular-material-extensions/google-maps-autocomplete');

    this.zoom = 10;
    this.latitude = 52.520008;
    this.longitude = 13.404954;

    this.setCurrentPosition();

  }

  private setCurrentPosition() {
    if ('geolocation' in navigator) {
      navigator.geolocation.getCurrentPosition((position) => {
        this.latitude = position.coords.latitude;
        this.longitude = position.coords.longitude;
        this.zoom = 12;
      });
    }
  }

  onAutocompleteSelected(result: PlaceResult) {
    console.log('onAutocompleteSelected: ', result);
  }

  onLocationSelected(location: Location) {
    console.log('onLocationSelected: ', location);
    this.latitude = location.latitude;
    this.longitude = location.longitude;
  }

  onGermanAddressMapped($event: GermanAddress) {
    console.log('onGermanAddressMapped', $event);
  }

}

反应表单示例


<form [formGroup]="addressFormGroup">
  <mat-search-google-maps-autocomplete formControlName="address">
  </mat-search-google-maps-autocomplete>

  // OR

  <mat-google-maps-autocomplete formControlName="address">
  </mat-google-maps-autocomplete>

</form>

import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  addressFormGroup: FormGroup;

  ngOnInit(): void {
    this.addressFormGroup = new FormGroup({
      address: new FormControl(),
    });

    this.addressFormGroup.get('address').valueChanges.subscribe(value => console.log('value changed', value))
  }
}

API - 更多信息请访问官方文档 地图 JavaScript API

matGoogleMapsAutocomplete

选项绑定类型默认说明
价值Input()地方救济;- 说吧
地址Input()地点字符串;- 说吧
国家Input()字符串字符串[ ];- 说吧
仅存的地方Input()布尔- 说吧可用于指示自动完整部件只获取 Place ID。 在自动完整对象上调用 getPlace( ) 时, 可用的 PlaceResult 将只设置位置 ID、 类型和名称属性 。 您可以使用返回的地址ID, 并使用 Places, Geocoding, 方向或远程矩阵服务 .
严格边界Input()布尔- 说吧是一个布尔来指定 API 是否只必须返回严格在指定界限所定义区域内的位置 。 API即使匹配用户输入,也不会返回此区域以外的结果.
类型Input()字符串 []- 说吧一组类型指定了明确的类型或类型集合,如下文所支持的类型所列出. 如果没有指定,则返回所有类型。 一般来说,只允许单一类型。 例外是,您可以安全地混合地理代码和建立类型,但请注意,这将具有与指定任何类型相同的效果. 支持的类型如下:.
类型Input()字符串- 说吧
自动完成选项Input()自动完成选项- 说吧所有以上输入在一个对象中! 传递到此对象的数据如果存在, 将会与输入合并
变化Output()地点字符串无效
自动完成Output()地点- 说吧当通过 google 地图自动完成组件选择一个位置时, 事件将被启动
在德文地址夹上Output()德国语地址- 说吧当一个位置被选中并映射到德国地址界面时, 事件将被解除
选中位置Output()地点- 说吧当通过 google 地图自动完成组件选择一个位置时, 事件将被启动

支持类型

类型说明
地理编码指示Places服务只返回地理编码结果,而不是商业结果.
地址指示 Places 服务只返回带有精确地址的地理编码结果 .
设立指示 Places 服务只返回业务结果 .
区域指示 Places 服务返回符合以下类型的任何结果: 地点、 子地点、 邮政 代码、 国家、 行政 地区1、 行政 地区2
城市指示地点服务处返回符合地点或行政区域3的结果.

mat-google-maps-autocomplete

包括所有内容 matGoogleMapsAutocomplete +以下各项

选项绑定类型默认说明
地址标签文字Input()字符串;使用组件的地址不言自明
占位符文本Input()字符串;请输入地址不言自明
需要的错误文本Input()字符串;需要地址吗不言自明
无效的错误文本Input()字符串;地址无效不言自明
外观Input()外观字符串;外观

mat-search-google-maps-autocomplete

选项绑定类型默认说明
搜索BarApearance 选项Input()外观字符串;外观
外观Input()外观字符串;外观
搜索地址标签Input()字符串;Search Address输入标签
街道Name 标签Input()字符串;Street输入标签
街道编号标签Input()字符串;Nr.输入标签
邮政编码标签Input()字符串;PLZ输入标签
标签附近Input()字符串;Locality输入标签
方位标签Input()字符串;Locality输入标签
显示维度Input()布尔;false输入标签 - 是否显示节能
只读Input()布尔;false只读输入
禁用搜索Input()布尔;false禁用用户搜索一个地方
价值Input()GermanAddress· ;- 说吧该组件的初始值
国家Input()字符串字符串[ ];- 说吧
仅存的地方Input()布尔- 说吧可用于指示自动完整部件只获取 Place ID。 在自动完整对象上调用 getPlace( ) 时, 可用的 PlaceResult 将只设置位置 ID、 类型和名称属性 。 您可以使用返回的地址ID, 并使用 Places, Geocoding, 方向或远程矩阵服务 .
严格边界Input()布尔- 说吧是一个布尔来指定 API 是否只必须返回严格在指定界限所定义区域内的位置 。 API即使匹配用户输入,也不会返回此区域以外的结果.
类型Input()字符串 []- 说吧一组类型指定了明确的类型或类型集合,如下文所支持的类型所列出. 如果没有指定,则返回所有类型。 一般来说,只允许单一类型。 例外是,您可以安全地混合地理代码和建立类型,但请注意,这将具有与指定任何类型相同的效果. 支持的类型如下:.
类型Input()字符串- 说吧
在德文地址夹上Output()事件编辑器字符串;外观

@angular-material-extensions/google-maps-autocomplete


<mat-card>
  <mat-card-title>Auto Parse Address</mat-card-title>
  <mat-card-content>
    <!-- #######   here we go !! ######-->
    <mat-search-google-maps-autocomplete appearance="outline"
                                         country="de"
                                         (onGermanAddressMapped)="onGermanAddressMapped($event)">
      >
    </mat-search-google-maps-autocomplete>
  </mat-card-content>
</mat-card>
import {Appearance, GermanAddress, Location} from '@angular-material-extensions/google-maps-autocomplete';

onGermanAddressMapped($event;
:
GermanAddress;
)
{
  console.log('onGermanAddressMapped', $event);
}

文档

请检查完 文档 这里 或遵循 正式 教程

本地运行 Demo 应用程序

$ git clone https://github.com/angular-material-extensions/google-maps-autocomplete.git
  • 链接 @angular-material-extension/google-maps-自动完成 软件包
$ gulp link
  • 导航到演示应用程序目录, 安装依赖并服务应用程序
$ cd demo && npm i && npm start
  • 该应用程序现在由 http://localhost:4200/

发展

  1. 复制这个 还原
  2. 通过运行安装依赖关系 npm i
  3. 转到 lib 目录 projects/angular-material-extensions/google-maps-autocomplete
  4. 建立图书馆 npm run build

其他角图书馆


支助

由开发商建造


谁在使用ngx -mailto? 伟大的应用程序?

  1. Nahaus.de - Digitale und automatisierte Immobileenverwaltung 软件公司 私人 Vermieter und Hausverwaltungen

你错过了你的项目还是你的应用? 公关我发表在读本上


许可证

版权(c) 2019-2024 安东尼·纳哈斯获得麻省理工学院许可 (麻省理工学院)

angular-material-extensions's logo

版本与发布记录

@angular-material-extensions/google-maps-autocomplete 共发布 46 个版本,首次发布于 2018/06/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
16.4.0latest2024/09/212 年前
16.3.12024/03/142 年前
16.3.02024/03/142 年前
16.2.32024/03/142 年前
16.2.22024/03/142 年前
16.2.12024/03/142 年前

关于 @angular-material-extensions/google-maps-autocomplete 的常见问题

@angular-material-extensions/google-maps-autocomplete 是什么?

用角和材料设计构建的google-maps自动完成输入组件和指令

如何安装 @angular-material-extensions/google-maps-autocomplete?

在项目目录运行 npm install @angular-material-extensions/google-maps-autocomplete,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(^16.x)、@angular/core(^16.x)、@angular/platform-browser(^16.x)、@angular/flex-layout(^15.0.0-beta.42)、@angular/forms(^16.x)、@angular/cdk(^16.x)、@angular/material(^16.x)、@types/googlemaps(~3.43.3)、rxjs(^7.x)、zone.js(~0.13.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@angular-material-extensions/google-maps-autocomplete 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@angular-material-extensions/google-maps-autocomplete 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@angular-material-extensions/google-maps-autocomplete 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@angular-material-extensions/google-maps-autocomplete 可以商用吗?

@angular-material-extensions/google-maps-autocomplete 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@angular-material-extensions/google-maps-autocomplete 的下载量有多少?

根据 npm 官方下载统计,@angular-material-extensions/google-maps-autocomplete 在 2026/10/06 – 2026/11/04 这 30 天内被下载 9,617 次,日均约 321 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@angular-material-extensions/google-maps-autocomplete 还在维护吗?

最新版本 16.4.0 发布于 2024/09/21(2 年前);至今共发布 46 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/06/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。