搜索分类、插件与代码仓

插件详情v1.5.2

google_geocoding_api

此包实现了 Google 地理编码 API,支持默认和反向地理搜索

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.3万
喜欢数
41
Pub 分数
160

安装插件

flutter pub add google_geocoding_api

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

google_geocoding_api 包提供了一种简单的方法,将 Google 地理编码 API 集成到 Flutter 应用程序中,支持正向和反向地理定位搜索。它允许用户将地址转换为地理坐标,反之亦然,支持多种平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。该包通过简洁易用的方法简化了 API 交互,非常适合在应用程序中实现基于位置的功能。使用该包需要有效的 Google Cloud Platform API 密钥。

适合场景

  • 地址转坐标转换
  • 位置详情的逆地理编码
  • 基于地图的应用位置搜索
  • 位置感知天气应用
  • 配送和物流跟踪

主要特点

  • 支持正向和反向地理编码
  • 跨平台兼容性
  • 简单的 API 集成
  • 内置错误处理
  • 需要 Google Cloud API 密钥

适合对象

  • 需要位置服务的移动和网页应用
  • 需要地址解析的应用程序
  • 使用 Google 地图后端的开发人员
  • 基于位置的分析工具
  • 实时导航应用

使用建议

  • 需要 Google Cloud Platform API 密钥
  • 根据查询量可能会产生使用费用
  • 速率限制已应用
  • 需要互联网连接
  • API 密钥在生产环境中必须得到保护

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub License: MIT

Buy Me A Coffee


Introduction

This package implement Google Geocoding API with only dart dependency(without flutter).
Before working with the package, be sure to read Before you begin and create an API key in Google Developer Console.

USAGE

Geocoding (latitude/longitude lookup)

This is example code how to use Geocoding Search. Before use it please read Geocoding (latitude/longitude lookup)

import 'package:google_geocoding_api/google_geocoding_api.dart';

Future<void> main() async {
  const String googelApiKey = 'YOUR_API_KEY';
  final bool isDebugMode = true;  
  final api = GoogleGeocodingApi(googelApiKey, isLogged: isDebugMode);  
  final searchResults = await api.search(
    'Boston',
    language: 'en',
  );
}

Reverse geocoding (address lookup)

This is example code how to use Geocoding Reverse Search. Before use it please read Reverse geocoding (address lookup)

import 'package:google_geocoding_api/google_geocoding_api.dart';

Future<void> main() async {
  const String googelApiKey = 'YOUR_API_KEY';
  final bool isDebugMode = true;  
  final api = GoogleGeocodingApi(googelApiKey, isLogged: isDebugMode);  
  final reversedSearchResults = await api.reverse(
    '42.360083,-71.05888',
    language: 'en',
  );
}

Place geocoding

This is example code how to use Place Geocoding. Before use it please read Place Geocoding

import 'package:google_geocoding_api/google_geocoding_api.dart';

Future<void> main() async {
  const String googelApiKey = 'YOUR_API_KEY';
  final bool isDebugMode = true;  
  final api = GoogleGeocodingApi(googelApiKey, isLogged: isDebugMode);  
  final placeSearchResults = await api.placeGeocoding(
    'ChIJd8BlQ2BZwokRAFUEcm_qrcA',
    language: 'en',
  );
}

Pretty Address

Now you can use .mapToPretty() to get an instance of GeocodingPrettyAddress instance containing address, city, country, latitude, longitude, postalCode, state, countryCode, streetNumber, streetName, placeId.

Attention: The feature is experimental and may not work exactly as you need. Any suggestions for improvement may be written in the Issue Tracker.

  final placeSearchResults = await api.placeGeocoding(
    'ChIJd8BlQ2BZwokRAFUEcm_qrcA',
    language: 'en',
  );
  
  final prettyAddress = placeSearchResults.results.firstOrNull?.mapToPretty();

  if (prettyAddress == null) {
    return null;
  }

  print(prettyAddress.postalCode);
  print(prettyAddress.streetNumber);
  print(prettyAddress.streetName);
  print(prettyAddress.city);
  print(prettyAddress.state);
  print(prettyAddress.placeId);
  print(prettyAddress.country);
  print(prettyAddress.address);
  print(prettyAddress.countryCode);
  print(prettyAddress.latitude);
  print(prettyAddress.longitude);

Contact and bugs

Use Issue Tracker for any questions or bug reports.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。