কোনও লোকেশন রিভার্স জিওকোড করুন

ইউরোপীয় অর্থনৈতিক অঞ্চল (EEA)-এর ডেভেলপার

  ম্যাপে বেশিক্ষণ প্রেস করে রাখলে, জেস্টারের কোঅর্ডিনেট রিভার্স জিওকোডিং পরিষেবায় পাঠানো হয়। সফল হলে, ফলাফল সহ একটি তথ্য উইন্ডো সহ একটি মার্কার ম্যাপে যোগ করা হয়।

শুরু করুন

স্যাম্পেল কোড ব্যবহার করে দেখার আগে, আপনাকে ডেভেলপমেন্ট এনভায়রনমেন্ট কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS-এর জন্য Maps SDK কোড স্যাম্পেল দেখুন।

কোড দেখুন

Swift

import GoogleMaps
import UIKit

// Sample code for GeoCoder service.
class GeocoderViewController: UIViewController {

  private lazy var mapView: GMSMapView = {
    let camera = GMSCameraPosition(latitude: -33.868, longitude: 151.2086, zoom: 12)
    return GMSMapView(frame: .zero, camera: camera)
  }()

  private lazy var geocoder = GMSGeocoder()

  override func loadView() {
    view = mapView
    mapView.delegate = self
  }
}

extension GeocoderViewController: GMSMapViewDelegate {
  func mapView(_ mapView: GMSMapView, didLongPressAt coordinate: CLLocationCoordinate2D) {
    // On a long press, reverse geocode this location.
    geocoder.reverseGeocodeCoordinate(coordinate) { response, error in
      guard let address = response?.firstResult() else {
        let errorMessage = error.map { String(describing: $0) } ?? "<no error>"
        print(
          "Could not reverse geocode point (\(coordinate.latitude), \(coordinate.longitude)): \(errorMessage)"
        )
        return
      }
      print("Geocoder result: \(address)")
      let marker = GMSMarker(position: address.coordinate)
      marker.appearAnimation = .pop
      marker.map = mapView

      guard let lines = address.lines, let title = lines.first else { return }
      marker.title = title
      if lines.count > 1 {
        marker.snippet = lines[1]
      }
    }
  }
}
      

Objective-C

#import "GoogleMapsDemos/Samples/GeocoderViewController.h"

#import <GoogleMaps/GoogleMaps.h>

@implementation GeocoderViewController {
  GMSMapView *_mapView;
  GMSGeocoder *_geocoder;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                          longitude:151.2086
                                                               zoom:12];

  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  _mapView.delegate = self;

  _geocoder = [[GMSGeocoder alloc] init];

  self.view = _mapView;
}

- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate {
  // On a long press, reverse geocode this location.
  __weak __typeof__(self) weakSelf = self;
  GMSReverseGeocodeCallback handler = ^(GMSReverseGeocodeResponse *response, NSError *error) {
    [weakSelf handleResponse:response coordinate:coordinate error:error];
  };
  [_geocoder reverseGeocodeCoordinate:coordinate completionHandler:handler];
}

- (void)handleResponse:(nullable GMSReverseGeocodeResponse *)response
            coordinate:(CLLocationCoordinate2D)coordinate
                 error:(nullable NSError *)error {
  GMSAddress *address = response.firstResult;
  if (address) {
    NSLog(@"Geocoder result: %@", address);

    GMSMarker *marker = [GMSMarker markerWithPosition:address.coordinate];
    NSArray<NSString *> *lines = [address lines];

    marker.title = [lines firstObject];
    if (lines.count > 1) {
      marker.snippet = [lines objectAtIndex:1];
    }

    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.map = _mapView;
  } else {
    NSLog(@"Could not reverse geocode point (%f,%f): %@", coordinate.latitude, coordinate.longitude,
          error);
  }
}

@end
      

স্থানীয়ভাবে সম্পূর্ণ স্যাম্পেল অ্যাপ রান করুন

iOS-এর জন্য Maps SDK স্যাম্পেল অ্যাপ GitHub থেকে ডাউনলোড আর্কাইভ হিসেবে উপলভ্য। iOS-এর জন্য Maps SDK স্যাম্পেল অ্যাপ ইনস্টল ও ব্যবহার করে দেখতে এইসব ধাপ অনুসরণ করুন।

  1. লোকাল ডিরেক্টরিতে স্যাম্পেল রিপোজিটরি ক্লোন করতে git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git রান করুন।
  2. টার্মিনাল উইন্ডো খুলে, যে ডিরেক্টরিতে স্যাম্পেল ফাইল ক্লোন করেছেন সেখানে নেভিগেট করুন এবং GoogleMaps ডিরেক্টরিতে ড্রিল ডাউন করুন:

    Swift

    cd maps-sdk-for-ios-samples/GoogleMaps-Swift
    open GoogleMapsSwiftXCFrameworkDemos.xcodeproj

    Objective-C

    cd maps-sdk-for-ios-samples-main/GoogleMaps
    open GoogleMapsDemos.xcodeproj
  3. Xcode প্রোজেক্টে, ফাইল > প্যাকেজ ডিপেন্ডেন্সি যোগ করুন বিকল্পে যান। URL হিসেবে https://github.com/googlemaps/ios-maps-sdk লিখুন, প্যাকেজটি নিয়ে আসার জন্য Enter প্রেস করুন এবং প্যাকেজ যোগ করুন বিকল্পে ক্লিক করুন।
  4. Xcode-এ, বর্তমান স্কিম সহ অ্যাপ তৈরি করতে কম্পাইল বোতাম প্রেস করুন। বিল্ডে কোনও সমস্যা হলে, আপনাকে Swift-এর জন্য SDKConstants.swift ফাইলে অথবা Objective-C-এর জন্য SDKDemoAPIKey.h ফাইলে API key লিখতে বলা হবে।
  5. iOS-এর জন্য Maps SDK চালু আছে এমন প্রোজেক্ট থেকে API কী পান।
  6. Swift-এর জন্য SDKConstants.swift ফাইল অথবাSDKDemoAPIKey.h Objective-C-এর জন্য ফাইল এডিট করুন এবং আপনার API কী apiKey অথবা kAPIKey কনস্ট্যান্টের সংজ্ঞায় পেস্ট করুন। যেমন:

    Swift

    static let apiKey = "YOUR_API_KEY"

    Objective-C

    static NSString *const kAPIKey = @"YOUR_API_KEY";
  7. SDKConstants.swift ফাইল (Swift) বাSDKDemoAPIKey.h ফাইল (Objective-C)-এ, নিম্নলিখিত লাইনটি সরিয়ে দিন, কারণ এটি ব্যবহারকারীর-নির্ধারিত সমস্যা রেজিস্টার করতে ব্যবহার করা হয়:

    Swift

    #error (Register for API Key and insert here. Then delete this line.)

    Objective-C

    #error Register for API Key and insert here.
  8. প্রোজেক্ট তৈরি করে রান করুন। iOS সিমুলেটর উইন্ডো দেখা যাবে, যেখানে Maps SDK ডেমো-এর তালিকা দেখানো হবে।
  9. iOS-এর জন্য Maps SDK-এর কোনও ফিচার নিয়ে পরীক্ষা করতে, দেখানো বিকল্পগুলির মধ্যে থেকে একটি বেছে নিন।
  10. GoogleMapsDemos-কে আপনার লোকেশন অ্যাক্সেস করার অনুমতি দিতে বলা হলে, অনুমতি দিন বিকল্পটি বেছে নিন।