GoogleMapsHelper

https://github.com/xeieshan/GoogleMapsHelper

КАК ИСПОЛЬЗОВАТЬ

С помощью AFNetworking:

[[AFGoogleMapsHelper sharedAFGoogleMapsHelper] geocodeAddressString:@"Arsenal Emirates" components:@{} completionHandler:^(MOGoogleGeocodeList *googleGeoCodeList, SPGoogleGeoCoderResponse responseCode, NSString *message) {
    
}];

CLLocationCoordinate2D emiratesStadium = { 51.555747, -0.108309};
CLLocationCoordinate2D stamfordBridge = { 51.481690, -0.190999 };

[[AFGoogleMapsHelper sharedAFGoogleMapsHelper] reverseGeocodeCoordinate:(emiratesStadium) resultTypes:@[] locationTypes:@[] completionHandler:^(MOGoogleGeocodeList *googleGeoCodeList, SPGoogleGeoCoderResponse responseCode, NSString *message) {
    
}];

[[AFGoogleMapsHelper sharedAFGoogleMapsHelper] getAutoCompleteFromGoogle:@"Arsenal Emirates Stadium, london" andAutoComplete:^(MOGoogleAutoCompleteList *googleAutocompleteList, SPGoogleGeoCoderResponse responseCode, NSString *message) {
    
}];

[[AFGoogleMapsHelper sharedAFGoogleMapsHelper] getDirections:emiratesStadium andCoordinateDestination:stamfordBridge andDrawPoints:^{
    
} andPlaceMarks:^(MKPolyline *polyLine, NSString *distance, NSString *duration, NSString *startAddress, NSString *endAddress, NSMutableArray *polyLineSetArray, NSMutableArray *directionsSetArray, NSMutableArray *distanceSetArray) {
    
}];

С помощью SVHTTPClient:

[[SVGoogleMapsHelper sharedGoogleMapHelper] geocodeAddressString:@"Arsenal Emirates" components:@{} completionHandler:^(MOGoogleGeocodeList *googleGeoCodeList, SPGoogleGeoCoderResponse responseCode, NSString *message) {
    
}];


[[SVGoogleMapsHelper sharedGoogleMapHelper] reverseGeocodeCoordinate:(emiratesStadium) resultTypes:@[] locationTypes:@[] completionHandler:^(MOGoogleGeocodeList *googleGeoCodeList, SPGoogleGeoCoderResponse responseCode, NSString *message) {
    
}];

[[SVGoogleMapsHelper sharedGoogleMapHelper] getAutoCompleteFromGoogle:@"Arsenal Emirates Stadium, london" andAutoComplete:^(MOGoogleAutoCompleteList *googleAutocompleteList, SPGoogleGeoCoderResponse responseCode, NSString *message) {
    
}];

[[SVGoogleMapsHelper sharedGoogleMapHelper] getDirections:emiratesStadium andCoordinateDestination:stamfordBridge andDrawPoints:^{
    
} andPlaceMarks:^(MKPolyline *polyLine, NSString *distance, NSString *duration, NSString *startAddress, NSString *endAddress, NSMutableArray *polyLineSetArray, NSMutableArray *directionsSetArray, NSMutableArray *distanceSetArray) {
    
}];

1- Геокод (Geocode)

Возвращает следующие элементы:

  • MOGoogleGeocodeList *googleGeoCodeList,
  • SPGoogleGeoCoderResponse responseCode,
  • NSString *message

Геокод @»Arsenal Emirates», вывести в консоль googleGeoCodeList->_results->[0]:

{ "formatted_address" = "Hornsey Rd, London N7 7AJ, UK"; geometry = { bounds = { }; location = { lat = "51.5548885"; lng = "-0.108438"; }; "location_type" = APPROXIMATE; viewport = { northeast = { lat = "51.55623748029149"; lng = "-0.107089019708498"; }; southwest = { lat = "51.5535395197085"; lng = "-0.109786980291502"; }; }; }; kMOGoogleGeocodePlacemarksAddressComponents = ( { kMOAddressComponentsTypes = ( route ); "long_name" = "Hornsey Road"; "short_name" = "Hornsey Rd"; }, { kMOAddressComponentsTypes = ( "postal_town" ); "long_name" = London; "short_name" = London; }, { kMOAddressComponentsTypes = ( "administrative_area_level_2", political ); "long_name" = "Greater London"; "short_name" = "Greater London"; }, { kMOAddressComponentsTypes = ( "administrative_area_level_1", political ); "long_name" = England; "short_name" = England; }, { kMOAddressComponentsTypes = ( country, political ); "long_name" = "United Kingdom"; "short_name" = GB; }, { kMOAddressComponentsTypes = ( "postal_code" ); "long_name" = "N7 7AJ"; "short_name" = "N7 7AJ"; } ); kMOGoogleGeocodePlacemarksTypes = ( establishment, "point_of_interest", stadium ); "place_id" = "ChIJO14pRXYbdkgRkM-CgzxxADY"; }

2- Обратный геокод (Reverse Geocode)

Возвращает следующие элементы:

  • MOGoogleGeocodeList *googleGeoCodeList,
  • SPGoogleGeoCoderResponse responseCode,
  • NSString *message

Лог первого элемента:

<__NSArrayI 0x6080000b1b20>( { "formatted_address" = "Emirates Stadium, London, UK"; geometry = { bounds = { northeast = { lat = "51.5561569"; lng = "-0.1069905"; }; southwest = { lat = "51.5539356"; lng = "-0.1098853"; }; }; location = { lat = "51.55572979999999"; lng = "-0.1083118"; }; "location_type" = ROOFTOP; viewport = { northeast = { lat = "51.5563952302915"; lng = "-0.1069905"; }; southwest = { lat = "51.5536972697085"; lng = "-0.1098853"; }; }; }; kMOGoogleGeocodePlacemarksAddressComponents = ( { kMOAddressComponentsTypes = ( premise ); "long_name" = "Emirates Stadium"; "short_name" = "Emirates Stadium"; }, { kMOAddressComponentsTypes = ( locality, political ); "long_name" = London; "short_name" = London; }, { kMOAddressComponentsTypes = ( "postal_town" ); "long_name" = London; "short_name" = London; }, { kMOAddressComponentsTypes = ( "administrative_area_level_2", political ); "long_name" = "Greater London"; "short_name" = "Greater London"; }, { kMOAddressComponentsTypes = ( "administrative_area_level_1", political ); "long_name" = England; "short_name" = England; }, { kMOAddressComponentsTypes = ( country, political ); "long_name" = "United Kingdom"; "short_name" = GB; } ); kMOGoogleGeocodePlacemarksTypes = ( premise ); "place_id" = ChIJuaX4rXcbdkgRX7nJ4iCVzT0; }} )

3- Автозаполнение (Autocomplete)

Возвращает следующие элементы:

  • MOGoogleAutoCompleteList *googleAutocompleteList,
  • SPGoogleGeoCoderResponse responseCode,
  • NSString *message

Если искать по запросу @»Arsenal Emirates Stadium, london», получится 2 результата, лог первого:

Printing description of ((MOPredictions *)0x0000600000282b70): { description = "Arsenal Football Club, Emirates Stadium, Hornsey Road, London, United Kingdom"; id = 695fdbc199ef136a3674dc5c3946d0901be24cf2; kMOPredictionsMatchedSubstrings = ( { length = 7; offset = 0; }, { length = 16; offset = 23; }, { length = 6; offset = 55; } ); kMOPredictionsTerms = ( { offset = 0; value = "Arsenal Football Club"; }, { offset = 23; value = "Emirates Stadium"; }, { offset = 41; value = "Hornsey Road"; }, { offset = 55; value = London; }, { offset = 63; value = "United Kingdom"; } ); kMOPredictionsTypes = ( establishment ); "place_id" = ChIJq3Y4mXYbdkgRinA5RgGR5tA; reference = "CmRcAAAA3_03PcjmlvYYAMB56q1NSPHAa6o4s5OZlZzmqKWVzl6m8wQu8kIAHqSFzY8M_fJC6tbdt5vQSOylmlp6vu8hMJ0areyjFCiETtOb2e1qkM9a8TbnHRoIGK83-h0iy9EaEhCgUDC5ODRWWeKhZZmXh3wHGhRRAUwm4UFKR6a689AJXsADrqKFNA"; }

4- Направления (Directions)

Возвращает:

  • MKPolyline *polyLine,
  • NSString *distance,
  • NSString *duration,
  • NSString *startAddress,
  • NSString *endAddress,
  • NSMutableArray *polyLineSetArray,
  • NSMutableArray *directionsSetArray,
  • NSMutableArray *distanceSetArray in a block.

Ниже приводятся примеры для следующих данных:

CLLocationCoordinate2D emiratesStadium = { 51.555747, -0.108309};
CLLocationCoordinate2D stamfordBridge = { 51.481690, -0.190999 };

Длительность (duration):

42 mins

Расстояние (distance):

16.6 km

Начальный адрес (startAddress):

Citizen Rd, London N7, UK

Конечный адрес (endAddress):

19 Billing Pl, London SW10 9UN, UK

Объект polyline, который можно использовать для MKMapView:



    It also tells you Guidance strings which you can use :

        Head southwest on Citizen Rd toward Hornsey Rd/A103,
        Turn right onto Hornsey Rd/A103,
        Turn left onto Tollington Rd/A503Continue to follow A503,
        Continue straight onto Camden Rd/A503,
        Turn left onto Camden St/A400Continue to follow A400,
        Turn left onto Hampstead Rd/A400Continue to follow A400,
        Turn right onto Euston Rd,
        Merge onto Euston Rd/A501 via the ramp to Ring Road/A41/A40/KilburnContinue to follow A501,
        Keep right to continue on Marylebone Flyover/A40Continue to follow A40,
        Take the A3220 ramp to Hammersmith/Shepherd's Bush/White City/Earls Court,
        At the roundabout, take the 1st exit onto W Cross Rte/A3220,
        At the roundabout, take the 2nd exit onto Holland Rd/A3220Continue to follow A3220,
        Keep right to continue on Warwick Gardens/A3220,
        Turn left onto Pembroke Rd/A3220Continue to follow A3220,
        Continue straight onto Earls Ct Rd/A3220Continue to follow A3220,
        Turn right onto Fulham Rd/A308Continue to follow Fulham Rd,
        Turn right,
        Turn right,
        Turn left
        Destination will be on the left

Убедитесь, что вы добавили в проект AFNetworking, SVProgressHUD, SVHTTPClient

Cocoapods:

        pod 'SVHTTPRequest', '~> 0.5'
        pod 'AFNetworking', '~> 3.0'
        pod 'SVProgressHUD'

Также нужно добавить условие в info.plist:

App Transport > Arbitrary loads allow : YES

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *