LPGoogleFunctions 1.2.3

LPGoogleFunctions 1.2.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年3月

Luka Penger维护。



  • 作者:
  • Luka Penger

LPGoogleFunctions是一个iOS库,提供了访问某些Google API函数的便捷方式。

https://developers.google.com/

由Luka Penger创建 http://lukapenger.eu

示例

  • LPPlacesAutocompleteService
  • LPStaticMapImagesService
  • LPStreetViewImagesService
  • LPSpeakService
  • LPDistanceMatrixService

ScreenShots ScreenShots ScreenShots ScreenShots ScreenShots

用法

如果要将该组件通过CocoaPods作为Pod项目包含,请在Podfile中添加以下行:

pod "LPGoogleFunctions"

ARC

LPGoogleFunctions使用ARC(自动引用计数)。

如果您在非ARC项目中使用LPGoogleFunctions,则需要在每个LPGoogleFunctions源文件上设置-fobjc-arc编译器标志。

在Xcode中设置编译器标志,转到您的活动目标并选择“构建设置”选项卡。现在选择所有LPGoogleFunctions源文件,按Enter键,插入-fobjc-arc然后“完成”,禁用LPGoogleFunctions的ARC。

方向服务

Google Directions API是一个通过HTTP请求计算两个位置之间方向的API服务。您可以搜索几种交通方式的路线,包括公共交通、驾车、步行或骑自行车。方向可以指定起点、终点和经纬度坐标作为文本字符串(例如,“芝加哥,IL”或“达尔文,NT,澳大利亚”)或作为经纬度坐标。Direction API可以使用一系列经纬度坐标返回分段路线。

参数

  • 起点 - 您希望计算方向的纬度/经度值。
  • 终点 - 您希望计算方向的纬度/经度值。
  • 交通模式 - 在计算方向时指定要使用的交通方式。如果您将模式设置为“公共交通”,则还必须指定出发时间或到达时间。
  • 避免收费 - 表示计算的路线应避免指定的特性。
  • 单位 - 指定在显示结果时使用的单位系统。
  • 替代方案 - 如果设置为true,表示Direction服务可以在响应中提供多个路线替代方案。注意,提供路线替代方案可能会增加从服务器返回的响应时间。
  • 出发时间 - 指定希望的出发时间。
  • 到达时间 - 指定希望的到达时间。
  • 航标点。 - 指定一组航标点。航标点通过指定位置改变路线。航标点可以是经纬度坐标或地址(将被地理编码)。
- (void)loadDirectionsForOrigin:(LPLocation *)origin forDestination:(LPLocation *)destination directionsTravelMode:(LPGoogleDirectionsTravelMode)travelMode directionsAvoidTolls:(LPGoogleDirectionsAvoid)avoid directionsUnit:(LPGoogleDirectionsUnit)unit directionsAlternatives:(BOOL)alternatives departureTime:(NSDate *)departureTime arrivalTime:(NSDate *)arrivalTime waypoints:(NSArray *)waypoints successfulBlock:(void (^)(LPDirections *directions))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

可以使用块和委托方法。

- (void)googleFunctionsWillLoadDirections:(LPGoogleFunctions *)googleFunctions;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions didLoadDirections:(LPDirections *)directions;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions errorLoadingDirectionsWithStatus:(LPGoogleStatus)status;

街景图像服务

Google Maps 图像 API 使得将街景图像嵌入到图像视图变得简单。

参数

  • 位置 - (如40.457375,-80.009353)。或 地址 - (如Chagrin Falls, OH)。
  • 图像大小 - 指定图像输出的像素大小。
  • 方向 - 指示摄像头的罗盘方向。接受的值为0到360(两只值表示北,其中90表示东,180表示南)。如果未指定方向,则计算一个值,将该方向对准最近照片拍摄的点所指向的指定位置。
  • 视野 - 决定图像的水平视野。视野以度数表示,最大允许值为120。在处理固定大小的视口时(如固定大小的街景图像),视野本质上代表缩放,数字越小表示缩放级别越高。
  • 倾斜 - 指定摄像头相对于街景车辆的向上或向下角度。这通常是,但不仅限于,平坦的水平。正值将摄像头向上倾斜(90度表示直接向上)。负值将摄像头向下倾斜(-90度表示直接向下)。

位置方法

- (void)loadStreetViewImageForLocation:(LPLocation *)location imageSize:(CGSize)size heading:(float)heading fov:(float)fov pitch:(float)pitch successfulBlock:(void (^)(UIImage *image))successful failureBlock:(void (^)(NSError *error))failure;

地址方法

- (void)loadStreetViewImageForAddress:(NSString *)address imageSize:(CGSize)size heading:(float)heading fov:(float)fov pitch:(float)pitch successfulBlock:(void (^)(UIImage *image))successful failureBlock:(void (^)(NSError *error))failure;

成功的块将返回 UIImage。

静态地图图像服务

Google Maps 图像 API 使得将静态 Google Maps 图像嵌入到图像视图变得简单。

参数

  • 位置 - (如40.457375,-80.009353)。或 地址 - (如Chagrin Falls, OH)。定义地图的中心。
  • 缩放 - (如果不存在标记则必需)定义地图的缩放级别,该级别决定了地图的放大级别。此参数采用与所需区域缩放级别相对应的数值。
  • 图像大小 - 指定图像输出的像素大小。
  • 图像比例 - (可选)影响返回的像素数量。scale=2返回与scale=1相同的覆盖范围和详细程度,但像素数量加倍。这对于开发高分辨率显示或在生成用于打印的地图时非常有用。默认值为1。
  • 地图类型 - (可选)定义构建的地图类型。有几种可能的maptype值,包括 roadmap、satellite、hybrid 和 terrain。使用 LPGoogleMapType。
  • 标记数组 - (可选)定义要附加到图像中指定位置的一个或多个标记。此参数采用单个标记定义,参数用竖线字符(|)分隔。可以在同一个标记参数中放置多个具有相同样式的标记;您可以通过添加额外的标记参数来添加具有不同样式的额外标记。注意,如果您为地图提供了标记,则无需指定通常必需的中心和缩放参数。使用 LPMapImageMarker。

位置方法

- (void)loadStaticMapImageForLocation:(LPLocation *)location zoomLevel:(int)zoom imageSize:(CGSize)size imageScale:(int)scale mapType:(LPGoogleMapType)maptype markersArray:(NSArray *)markers successfulBlock:(void (^)(UIImage *image))successful failureBlock:(void (^)(NSError *error))failure;

地址方法

- (void)loadStaticMapImageForAddress:(NSString *)address zoomLevel:(int)zoom imageSize:(CGSize)size imageScale:(int)scale mapType:(LPGoogleMapType)maptype markersArray:(NSArray*)markers successfulBlock:(void (^)(UIImage *image))successful failureBlock:(void (^)(NSError *error))failure;

成功的块将返回 UIImage。

位置自动完成服务

Google Places 自动完成 API 是一种基于文字搜索词和可选地理边界的网页服务,它返回位置信息。该 API 可用于通过返回文本地理搜索时的位置(如企业、地址和兴趣点)来提供自动完成功能,用户输入时即可返回这些位置。

  • 输入 - 要搜索的文本字符串。位置服务将基于此字符串返回候选匹配项,并根据其感知相关性对结果进行排序。
  • 偏移量 - 服务用于预测的输入项中的字符位置。例如,如果输入是"Googl",完成点为3,则服务将匹配"Goo"。偏移量通常应设置为文本插入符的位置。如果没有提供偏移量,则服务将使用整个项。
  • 半径 - 返回位置结果的范围(以米为单位)。请注意,设置半径会偏重结果到指定区域,但可能无法完全限制结果在指定区域内。
  • 位置 - 您想为其检索位置信息的位置的点。必须指定为纬度,经度。
  • 位置类型 - 要返回的位置结果类型。如果没有指定类型,将返回所有类型。有关类型,请参阅LPPrediction.h。
  • 国家限制 - 国家必须以两个字符的形式传递。
- (void)loadPlacesAutocompleteForInput:(NSString *)input offset:(int)offset radius:(int)radius location:(LPLocation *)location placeType:(LPGooglePlaceType)placeType countryRestriction:(NSString *)countryRestriction successfulBlock:(void (^)(LPPlacesAutocomplete *placesAutocomplete))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

可以使用块和委托方法。

- (void)googleFunctionsWillLoadPlacesAutocomplete:(LPGoogleFunctions *)googleFunctions forInput:(NSString *)input;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions errorLoadingPlacesAutocompleteWithStatus:(LPGoogleStatus)status;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions didLoadPlacesAutocomplete:(LPPlacesAutocomplete *)placesAutocomplete;

位置详细信息参考服务

一旦您从位置搜索中获得了参考,您可以通过发起位置详细信息请求来请求有关特定场所或兴趣点的更多详细信息。位置详细信息请求返回有关指示位置的更全面信息,例如其完整地址、电话号码、用户评分和评论。

参数

  • 参考 - 唯一标识位置的文字标识符,从位置搜索中返回。
- (void)loadPlaceDetailsForReference:(NSString *)reference successfulBlock:(void (^)(LPPlaceDetailsResults *placeDetailsResults))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

可以使用块和委托方法。

- (void)googleFunctionsWillLoadPlaceDetailsResult:(LPGoogleFunctions *)googleFunctions forReference:(NSString *)reference;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions errorLoadingPlaceDetailsResultWithStatus:(LPGoogleStatus)status;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions didLoadPlaceDetailsResult:(LPPlaceDetailsResults *)placeDetailsResults;

Google文本到语音服务

Google语音文本。

参数

  • 文本 - 要转换的文本。
- (void)speakText:(NSString *)text failureBlock:(void (^)(NSError *error))failure;

地理编码服务

地理编码是将地址(例如"1600 Amphitheatre Parkway, Mountain View, CA")转换为地理坐标(例如纬度37.423021和经度-122.083739)的过程,这可以用于放置标记或定位地图。

参数

  • 位置 - (如40.457375,-80.009353)。或 地址 - (如Chagrin Falls, OH)。
  • 过滤组件 - 想要获取地理编码的组件过滤器。如果提供了地址,也将接受组件过滤器作为可选参数。有关组件,请参阅LPGeocodingFilter.h。

位置方法

- (void)loadGeocodingForLocation:(LPLocation *)location filterComponents:(NSArray *)filterComponents successfulBlock:(void (^)(LPGeocodingResults *geocodingResults))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

地址方法

- (void)loadGeocodingForAddress:(NSString *)address filterComponents:(NSArray *)filterComponents successfulBlock:(void (^)(LPGeocodingResults *geocodingResults))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

可以使用块和委托方法。

- (void)googleFunctionsWillLoadGeocoding:(LPGoogleFunctions *)googleFunctions forAddress:(NSString *)address filterComponents:(NSArray *)filterComponents;
- (void)googleFunctionsWillLoadGeocoding:(LPGoogleFunctions *)googleFunctions forLocation:(LPLocation *)location filterComponents:(NSArray *)filterComponents;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions errorLoadingGeocodingWithStatus:(LPGoogleStatus)status;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions didLoadGeocodingResults:(LPGeocodingResults *)geocodingResults;

位置自动补全加详细信息服务

位置自动补全 + 位置详细信息

参数

  • 输入 - 要搜索的文本字符串。位置服务将基于此字符串返回候选匹配项,并根据其感知相关性对结果进行排序。
  • 偏移量 - 服务用于预测的输入项中的字符位置。例如,如果输入是"Googl",完成点为3,则服务将匹配"Goo"。偏移量通常应设置为文本插入符的位置。如果没有提供偏移量,则服务将使用整个项。
  • 半径 - 返回位置结果的范围(以米为单位)。请注意,设置半径会偏重结果到指定区域,但可能无法完全限制结果在指定区域内。
  • 位置 - 您想为其检索位置信息的位置的点。必须指定为纬度,经度。
  • 位置类型 - 要返回的位置结果类型。如果没有指定类型,将返回所有类型。有关类型,请参阅LPPrediction.h。
  • 国家限制 - 国家必须以两个字符的形式传递。
- (void)loadPlacesAutocompleteWithDetailsForInput:(NSString *)input offset:(int)offset radius:(int)radius location:(LPLocation *)location placeType:(LPGooglePlaceType)placeType countryRestriction:(NSString *)countryRestriction successfulBlock:(void (^)(NSArray *placesWithDetails))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

位置文本搜索服务

Google位置API文本搜索服务是一种基于字符串(例如"在纽约披萨"或"靠近Ottawa的鞋店")返回位置集信息的Web服务。

参数

  • 查询 - 要搜索的文本字符串,例如:"餐厅"。位置服务将基于此字符串生成候选匹配项,并按其感知相关性对结果进行排序。
  • 位置 - 检索位置信息的纬度/经度周围的位置。必须指定为纬度,经度。如果您指定了位置参数,您还必须指定半径参数。
  • 半径 - 定义了影响位置结果的距离(以米为单位)。允许的最大半径为50,000米。此区域内的结果将比搜索圈外的结果排名更高;然而,可能包括搜索半径外的重要结果。
- (void)loadPlaceTextSearchForQuery:(NSString *)query location:(LPLocation *)location radius:(int)radius successfulBlock:(void (^)(LPPlaceSearchResults *placeResults))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

可以使用块和委托方法。

- (void)googleFunctionsWillLoadPlaceSearch:(LPGoogleFunctions *)googleFunctions forQuery:(NSString *)guery;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions didLoadPlaceSearch:(LPPlaceSearchResults *)placeResults;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions errorLoadingPlaceSearchWithStatus:(LPGoogleStatus)status;

位置照片参考服务

地点照片服务是一个只读API,允许您轻松地将高分辨率照片内容添加到您的应用中。照片服务使您能够访问存储在地点和谷歌+本地的数据库中的数百万张照片。当您使用地点搜索或地点详情请求搜索地点时,会返回相关照片内容的参考信息。照片服务允许您访问引用的照片,并将图像调整为适用于应用的优化尺寸。

参数

  • 参考 - 一个唯一标识照片的字符串标识符。照片参考从地点搜索或地点详情请求返回。
  • 最大高度 - 最大图像高度(接受介于1到1600之间的整数)。
  • 最大宽度 - 最小图像高度(接受介于1到1600之间的整数)。
- (void)loadPlacePhotoForReference:(NSString *)reference maxHeight:(int)maxHeight maxWidth:(int)maxWidth successfulBlock:(void (^)(UIImage *image))successful failureBlock:(void (^)(NSError *error))failure;

距离矩阵服务

谷歌距离矩阵API是一种提供起点和目的地矩阵旅行距离和时间的服务。返回的信息基于根据谷歌地图API计算出的推荐路线之间的信息,由包含每对距离和持续时间值的行组成。

参数

  • 起点 - LPLocation数组的集合 - 您希望从中计算路由的纬度/经度值。
  • 终点 - LPLocation数组的集合 - 您希望从中计算路由的纬度/经度值。
  • 交通模式 - 在计算方向时指定要使用的交通方式。如果您将模式设置为“公共交通”,则还必须指定出发时间或到达时间。
  • 避免收费 - 表示计算的路线应避免指定的特性。
  • 单位 - 指定在显示结果时使用的单位系统。
  • 出发时间 - 指定希望的出发时间。
- (void)loadDistanceMatrixForOrigins:(NSArray *)origins forDestinations:(NSArray *)destinations directionsTravelMode:(LPGoogleDistanceMatrixTravelMode)travelMode directionsAvoidTolls:(LPGoogleDistanceMatrixAvoid)avoid directionsUnit:(LPGoogleDistanceMatrixUnit)unit departureTime:(NSDate *)departureTime successfulBlock:(void (^)(LPDistanceMatrix *distanceMatrix))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

可以使用块和委托方法。

- (void)googleFunctionsWillLoadDistanceMatrix:(LPGoogleFunctions *)googleFunctions;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions didLoadDistanceMatrix:(LPDistanceMatrix *)distanceMatrix;
- (void)googleFunctions:(LPGoogleFunctions *)googleFunctions errorLoadingDistanceMatrixWithStatus:(LPGoogleStatus)status;

使用框架 - 库

  • UIKit框架
  • Foundation框架
  • CoreLocation框架
  • AVFoundation框架

LPGoogleFunctions使用AFNetworking库进行网络通信。 [https://github.com/AFNetworking/AFNetworking](https://github.com/AFNetworking/AFNetworking)

许可协议

此代码是根据MIT许可证的条款和条件进行分发的。

变更日志

每个LPGoogleFunctions版本简要总结可以在wiki上找到。