• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

LPGoogleFunctions is an iOS library that provides easy access to certain Google API functions.

LPGoogleFunctions

LPGoogleFunctions is an iOS library that provides easy access to certain Google API functions.

https://developers.google.com/

Created by Luka Penger http://lukapenger.eu

Examples

  • LPPlacesAutocompleteService
  • LPStaticMapImagesService
  • LPStreetViewImagesService
  • LPSpeakService
  • LPDistanceMatrixService

ScreenShots ScreenShots ScreenShots ScreenShots ScreenShots

Usage

If you'd like to include this component as a pod using CocoaPods, just add the following line to your Podfile:

pod "LPGoogleFunctions" and run pod install

Configure global variables in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	[[LPGoogleFunctions sharedInstance] setGoogleAPIBrowserKey:@"GOOGLE_API_KEY"];
	[[LPGoogleFunctions sharedInstance] setLanguageCode:@"en"];
}

ARC

LPGoogleFunctions uses ARC (Automatic Reference Counting).

If you are using LPGoogleFunctions in your non-arc project, you will need to set a -fobjc-arc compiler flag on all of the LPGoogleFunctions source files.

To set a compiler flag in Xcode, go to your active target and select the "Build Phases" tab. Now select all LPGoogleFunctions source files, press Enter, insert -fobjc-arc and then "Done" to disable ARC for LPGoogleFunctions.

Directions service

The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints.

Parameters:

  • Origin - The latitude/longitude value from which you wish to calculate directions.
  • Destination - The latitude/longitude value from which you wish to calculate directions.
  • Travel Mode - Specifies the mode of transport to use when calculating directions. If you set the mode to "transit" you must also specify either a departure time or an arrival time.
  • Avoid Tolls - Indicates that the calculated route(s) should avoid the indicated features.
  • Unit - Specifies the unit system to use when displaying results.
  • Alternatives - If set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server.
  • Departure time - Specifies the desired time of departure.
  • Arrival time Specifies the desired time of departure.
  • Waypoints. - Specifies an array of waypoints. Waypoints alter a route by routing it through the specified location(s). A waypoint is specified as either a latitude/longitude coordinate or as an address which will be geocoded.
- (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;

You can use blocks and delegate methods:

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

Street View Images service

The Google Maps Image APIs make it easy to embed a street view image into your image view.

Parameters:

  • Location - The location (such as 40.457375,-80.009353). or Address - The address (such as Chagrin Falls, OH).
  • Image Size - Specifies the output size of the image in pixels.
  • Heading - Indicates the compass heading of the camera. Accepted values are from 0 to 360 (both values indicating North, with 90 indicating East, and 180 South). If no heading is specified, a value will be calculated that directs the camera towards the specified location, from the point at which the closest photograph was taken.
  • Fov - Determines the horizontal field of view of the image. The field of view is expressed in degrees, with a maximum allowed value of 120. When dealing with a fixed-size viewport, as with a Street View image of a set size, field of view in essence represents zoom, with smaller numbers indicating a higher level of zoom.
  • Pitch - Specifies the up or down angle of the camera relative to the Street View vehicle. This is often, but not always, flat horizontal. Positive values angle the camera up (with 90 degrees indicating straight up). Negative values angle the camera down (with -90 indicating straight down).

Method for location:

- (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;

Method for address:

- (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;

Successful block will return UIImage.

Static Map Images service

The Google Maps Image APIs make it easy to embed a static Google Maps image into your image view.

Parameters:

  • Location - The location (such as 40.457375,-80.009353). or Address - The address (such as Chagrin Falls, OH). Defines the center of the map.
  • Zoom - (required if markers not present) defines the zoom level of the map, which determines the magnification level of the map. This parameter takes a numerical value corresponding to the zoom level of the region desired.
  • Image Size - Specifies the output size of the image in pixels.
  • Image Scale - (optional) affects the number of pixels that are returned. scale=2 returns twice as many pixels as scale=1 while retaining the same coverage area and level of detail (i.e. the contents of the map don't change). This is useful when developing for high-resolution displays, or when generating a map for printing. The default value is 1.
  • Map Type - (optional) defines the type of map to construct. There are several possible maptype values, including roadmap, satellite, hybrid, and terrain. Use LPGoogleMapType.
  • Markers Array - (optional) define one or more markers to attach to the image at specified locations. This parameter takes a single marker definition with parameters separated by the pipe character (|). Multiple markers may be placed within the same markers parameter as long as they exhibit the same style; you may add additional markers of differing styles by adding additional markers parameters. Note that if you supply markers for a map, you do not need to specify the (normally required) center and zoom parameters. Use LPMapImageMarker.

Method for location:

- (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;

Method for address:

- (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;

Successful block will return UIImage.

Places Autocomplete service

The Google Places Autocomplete API is a web service that returns Place information based on text search terms, and, optionally, geographic bounds. The API can be used to provide autocomplete functionality for text-based geographic searches, by returning Places such as businesses, addresses, and points of interest as a user types.

  • Input - The text string on which to search. The Place service will return candidate matches based on this string and order results based on their perceived relevance.
  • Offset - The character position in the input term at which the service uses text for predictions. For example, if the input is 'Googl' and the completion point is 3, the service will match on 'Goo'. The offset should generally be set to the position of the text caret. If no offset is supplied, the service will use the entire term.
  • Radius - The distance (in meters) within which to return Place results. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area.
  • Location - The point around which you wish to retrieve Place information. Must be specified as latitude,longitude.
  • Place Type - The types of Place results to return. If no type is specified, all types will be returned. See LPPrediction.h for types.
  • Country Restriction - The country must be passed as a two character.
- (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;

You can use blocks and delegate methods:

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

Place Details For Reference service

Once you have a reference from a Place Search, you can request more details about a particular establishment or point of interest by initiating a Place Details request. A Place Details request returns more comprehensive information about the indicated place such as its complete address, phone number, user rating and reviews.

Parameters:

  • Reference - A textual identifier that uniquely identifies a place, returned from a Place search.
- (void)loadPlaceDetailsForReference:(NSString *)reference successfulBlock:(void (^)(LPPlaceDetailsResults *placeDetailsResults))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

You can use blocks and delegate methods:

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

Google Text to Speech service

Google Speak Text.

Parameters:

  • Text - Text for convert.
- (void)speakText:(NSString *)text failureBlock:(void (^)(NSError *error))failure;

Geocoding service

Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map.

Parameters:

  • Location - The location (such as 40.457375,-80.009353). or Address - The address (such as Chagrin Falls, OH).
  • Filter Components - A component filter for which you wish to obtain a geocode. The components filter will also be accepted as an optional parameter if an address is provided. See LPGeocodingFilter.h for components.

Method for location:

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

Method for address:

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

You can use blocks and delegate methods:

- (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;

Place Autocomplete with Details service

Place Autocomplete + Place Details

Parameters:

  • Input - The text string on which to search. The Place service will return candidate matches based on this string and order results based on their perceived relevance.
  • Offset - The character position in the input term at which the service uses text for predictions. For example, if the input is 'Googl' and the completion point is 3, the service will match on 'Goo'. The offset should generally be set to the position of the text caret. If no offset is supplied, the service will use the entire term.
  • Radius - The distance (in meters) within which to return Place results. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area.
  • Location - The point around which you wish to retrieve Place information. Must be specified as latitude,longitude.
  • Place Type - The types of Place results to return. If no type is specified, all types will be returned. See LPPrediction.h for types.
  • Country Restriction - The country must be passed as a two character.
- (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;

Place Text Search service

The Google Places API Text Search Service is a web service that returns information about a set of Places based on a string β€” for example "pizza in New York" or "shoe stores near Ottawa".

Parameters:

  • Query - The text string on which to search, for example: "restaurant". The Place service will return candidate matches based on this string and order the results based on their perceived relevance.
  • Location - The latitude/longitude around which to retrieve Place information. This must be specified as latitude,longitude. If you specify a location parameter, you must also specify a radius parameter.
  • Radius - Defines the distance (in meters) within which to bias Place results. The maximum allowed radius is 50 000 meters. Results inside of this region will be ranked higher than results outside of the search circle; however, prominent results from outside of the search radius may be included.
- (void)loadPlaceTextSearchForQuery:(NSString *)query location:(LPLocation *)location radius:(int)radius successfulBlock:(void (^)(LPPlaceSearchResults *placeResults))successful failureBlock:(void (^)(LPGoogleStatus status))failure;

You can use blocks and delegate methods:

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

Place Photo for Reference service

The Places Photo service is a read-only API that allows you to easily add high quality photographic content to your application. The Photo service gives you access to the millions of photos stored in the Places and Google+ Local database. When you search for Places using either a Place Search or Place Details request, photo references will be returned for relevant photographic content. The Photo service lets you access the referenced photos, and resize the image to the optimal size for your application.

Parameters:

  • Reference - A string identifier that uniquely identifies a photo. Photo references are returned from either a Place Search or Place Details request.
  • Max Height - Max image height (accept an integer between 1 and 1600).
  • Max Width - Min image height (accept an integer between 1 and 1600).
- (void)loadPlacePhotoForReference:(NSString *)reference maxHeight:(int)maxHeight maxWidth:(int)maxWidth successfulBlock:(void (^)(UIImage *image))successful failureBlock:(void (^)(NSError *error))failure;

Distance Matrix service

The Google Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations. The information returned is based on the recommended route between start and end points, as calculated by the Google Maps API, and consists of rows containing duration and distance values for each pair.

Parameters:

  • Origins - Array of LPLocation - The latitude/longitude value from which you wish to calculate directions.
  • Destinations - Array of LPLocation - The latitude/longitude value from which you wish to calculate directions.
  • Travel Mode - Specifies the mode of transport to use when calculating directions. If you set the mode to "transit" you must also specify either a departure time or an arrival time.
  • Avoid Tolls - Indicates that the calculated route(s) should avoid the indicated features.
  • Unit - Specifies the unit system to use when displaying results.
  • Departure time - Specifies the desired time of departure.
- (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;

You can use blocks and delegate methods:

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

Uses Frameworks - Libraries

  • UIKit.framework
  • Foundation.framework
  • CoreLocation.framework
  • AVFoundation.framework

LPGoogleFunctions uses AFNetworking library for networking. https://github.com/AFNetworking/AFNetworking

License

This code is distributed under the terms and conditions of the MIT license.

Change log

A brief summary of each LPGoogleFunctions release can be found on the wiki.