মার্কার ইভেন্টগুলি পরিচালনা করুন

এই উদাহরণে দুটি মার্কার সহ একটি মানচিত্র দেখানো হয়েছে। যখন একটি মার্কার ট্যাপ করা হয়, তখন ক্যামেরাটি জুম করে এবং ঘোরায় নির্বাচিত মার্কারটিতে ফোকাস করে।

শুরু করুন

নমুনা কোডটি চেষ্টা করার আগে, আপনাকে অবশ্যই আপনার ডেভেলপমেন্ট পরিবেশ কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS কোড নমুনার জন্য Maps SDK দেখুন।

কোডটি দেখুন

সুইফট

import GoogleMaps
import UIKit

final class MarkerEventsViewController: UIViewController {

  private lazy var mapView: GMSMapView = {
    let camera = GMSCameraPosition(latitude: -37.81969, longitude: 144.966085, zoom: 4)
    return GMSMapView(frame: .zero, camera: camera)
  }()

  private var melbourneMarker = GMSMarker(
    position: CLLocationCoordinate2D(latitude: -37.81969, longitude: 144.966085))

  override func loadView() {
    let sydneyMarker = GMSMarker(
      position: CLLocationCoordinate2D(latitude: -33.8683, longitude: 151.2086))
    sydneyMarker.map = mapView
    melbourneMarker.map = mapView
    mapView.delegate = self
    view = mapView
  }
}

extension MarkerEventsViewController: GMSMapViewDelegate {
  func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    if marker == melbourneMarker {
      return UIImageView(image: UIImage(named: "Icon"))
    }
    return nil
  }

  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    // Animate to the marker
    CATransaction.begin()
    CATransaction.setAnimationDuration(3)
    let camera = GMSCameraPosition(target: marker.position, zoom: 8, bearing: 50, viewingAngle: 60)
    mapView.animate(to: camera)
    CATransaction.commit()

    // Melbourne marker has a InfoWindow so return false to allow markerInfoWindow to
    // fire. Also check that the marker isn't already selected so that the InfoWindow
    // doesn't close.
    if marker == melbourneMarker && mapView.selectedMarker != melbourneMarker {
      return false
    }
    return true
  }
}
      

অবজেক্টিভ-সি

#import "GoogleMapsDemos/Samples/MarkerEventsViewController.h"

#import <QuartzCore/QuartzCore.h>

#import <GoogleMaps/GoogleMaps.h>

@implementation MarkerEventsViewController {
  GMSMapView *_mapView;
  GMSMarker *_melbourneMarker;
  BOOL _rotating;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
                                                          longitude:144.966085
                                                               zoom:4];
  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
  sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  sydneyMarker.map = _mapView;

  _melbourneMarker = [[GMSMarker alloc] init];
  _melbourneMarker.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  _melbourneMarker.map = _mapView;

  _mapView.delegate = self;
  self.view = _mapView;
}

#pragma mark - GMSMapViewDelegate

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  if (marker == _melbourneMarker) {
    return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon"]];
  }

  return nil;
}

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
  GMSCameraPosition *camera = [[GMSCameraPosition alloc] initWithTarget:marker.position
                                                                   zoom:8
                                                                bearing:50
                                                           viewingAngle:60];
  // Animate to the marker
  [CATransaction begin];
  [CATransaction setAnimationDuration:3.f];  // 3 second animation
  [CATransaction setCompletionBlock:^{
    if (_rotating) {  // Animation was interrupted by orientation change.
      [CATransaction
          setDisableActions:true];  // Disable animation to avoid interruption from rotation.
      [_mapView animateToCameraPosition:camera];
    }
  }];

  [mapView animateToCameraPosition:camera];
  [CATransaction commit];

  // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to fire. Also check
  // that the marker isn't already selected so that the InfoWindow doesn't close.
  if (marker == _melbourneMarker && mapView.selectedMarker != _melbourneMarker) {
    return NO;
  }

  // The Tap has been handled so return YES
  return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  _rotating = true;
  [coordinator
      animateAlongsideTransition:nil
                      completion:^(
                          id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
                        _rotating = false;
                      }];
  [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end
      

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

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

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

    সুইফট

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

    অবজেক্টিভ-সি

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

    সুইফট

    static let apiKey = "YOUR_API_KEY"

    অবজেক্টিভ-সি

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

    সুইফট

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

    অবজেক্টিভ-সি

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

শুরু করুন

নমুনা কোডটি চেষ্টা করার আগে, আপনাকে অবশ্যই আপনার ডেভেলপমেন্ট পরিবেশ কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS কোড নমুনার জন্য Maps SDK দেখুন।

কোডটি দেখুন

সুইফট

import GoogleMaps
import UIKit

final class MarkerEventsViewController: UIViewController {

  private lazy var mapView: GMSMapView = {
    let camera = GMSCameraPosition(latitude: -37.81969, longitude: 144.966085, zoom: 4)
    return GMSMapView(frame: .zero, camera: camera)
  }()

  private var melbourneMarker = GMSMarker(
    position: CLLocationCoordinate2D(latitude: -37.81969, longitude: 144.966085))

  override func loadView() {
    let sydneyMarker = GMSMarker(
      position: CLLocationCoordinate2D(latitude: -33.8683, longitude: 151.2086))
    sydneyMarker.map = mapView
    melbourneMarker.map = mapView
    mapView.delegate = self
    view = mapView
  }
}

extension MarkerEventsViewController: GMSMapViewDelegate {
  func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    if marker == melbourneMarker {
      return UIImageView(image: UIImage(named: "Icon"))
    }
    return nil
  }

  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    // Animate to the marker
    CATransaction.begin()
    CATransaction.setAnimationDuration(3)
    let camera = GMSCameraPosition(target: marker.position, zoom: 8, bearing: 50, viewingAngle: 60)
    mapView.animate(to: camera)
    CATransaction.commit()

    // Melbourne marker has a InfoWindow so return false to allow markerInfoWindow to
    // fire. Also check that the marker isn't already selected so that the InfoWindow
    // doesn't close.
    if marker == melbourneMarker && mapView.selectedMarker != melbourneMarker {
      return false
    }
    return true
  }
}
      

অবজেক্টিভ-সি

#import "GoogleMapsDemos/Samples/MarkerEventsViewController.h"

#import <QuartzCore/QuartzCore.h>

#import <GoogleMaps/GoogleMaps.h>

@implementation MarkerEventsViewController {
  GMSMapView *_mapView;
  GMSMarker *_melbourneMarker;
  BOOL _rotating;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
                                                          longitude:144.966085
                                                               zoom:4];
  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
  sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  sydneyMarker.map = _mapView;

  _melbourneMarker = [[GMSMarker alloc] init];
  _melbourneMarker.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  _melbourneMarker.map = _mapView;

  _mapView.delegate = self;
  self.view = _mapView;
}

#pragma mark - GMSMapViewDelegate

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  if (marker == _melbourneMarker) {
    return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon"]];
  }

  return nil;
}

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
  GMSCameraPosition *camera = [[GMSCameraPosition alloc] initWithTarget:marker.position
                                                                   zoom:8
                                                                bearing:50
                                                           viewingAngle:60];
  // Animate to the marker
  [CATransaction begin];
  [CATransaction setAnimationDuration:3.f];  // 3 second animation
  [CATransaction setCompletionBlock:^{
    if (_rotating) {  // Animation was interrupted by orientation change.
      [CATransaction
          setDisableActions:true];  // Disable animation to avoid interruption from rotation.
      [_mapView animateToCameraPosition:camera];
    }
  }];

  [mapView animateToCameraPosition:camera];
  [CATransaction commit];

  // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to fire. Also check
  // that the marker isn't already selected so that the InfoWindow doesn't close.
  if (marker == _melbourneMarker && mapView.selectedMarker != _melbourneMarker) {
    return NO;
  }

  // The Tap has been handled so return YES
  return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  _rotating = true;
  [coordinator
      animateAlongsideTransition:nil
                      completion:^(
                          id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
                        _rotating = false;
                      }];
  [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end
      

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

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

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

    সুইফট

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

    অবজেক্টিভ-সি

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

    সুইফট

    static let apiKey = "YOUR_API_KEY"

    অবজেক্টিভ-সি

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

    সুইফট

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

    অবজেক্টিভ-সি

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

শুরু করুন

নমুনা কোডটি চেষ্টা করার আগে, আপনাকে অবশ্যই আপনার ডেভেলপমেন্ট পরিবেশ কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS কোড নমুনার জন্য Maps SDK দেখুন।

কোডটি দেখুন

সুইফট

import GoogleMaps
import UIKit

final class MarkerEventsViewController: UIViewController {

  private lazy var mapView: GMSMapView = {
    let camera = GMSCameraPosition(latitude: -37.81969, longitude: 144.966085, zoom: 4)
    return GMSMapView(frame: .zero, camera: camera)
  }()

  private var melbourneMarker = GMSMarker(
    position: CLLocationCoordinate2D(latitude: -37.81969, longitude: 144.966085))

  override func loadView() {
    let sydneyMarker = GMSMarker(
      position: CLLocationCoordinate2D(latitude: -33.8683, longitude: 151.2086))
    sydneyMarker.map = mapView
    melbourneMarker.map = mapView
    mapView.delegate = self
    view = mapView
  }
}

extension MarkerEventsViewController: GMSMapViewDelegate {
  func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    if marker == melbourneMarker {
      return UIImageView(image: UIImage(named: "Icon"))
    }
    return nil
  }

  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    // Animate to the marker
    CATransaction.begin()
    CATransaction.setAnimationDuration(3)
    let camera = GMSCameraPosition(target: marker.position, zoom: 8, bearing: 50, viewingAngle: 60)
    mapView.animate(to: camera)
    CATransaction.commit()

    // Melbourne marker has a InfoWindow so return false to allow markerInfoWindow to
    // fire. Also check that the marker isn't already selected so that the InfoWindow
    // doesn't close.
    if marker == melbourneMarker && mapView.selectedMarker != melbourneMarker {
      return false
    }
    return true
  }
}
      

অবজেক্টিভ-সি

#import "GoogleMapsDemos/Samples/MarkerEventsViewController.h"

#import <QuartzCore/QuartzCore.h>

#import <GoogleMaps/GoogleMaps.h>

@implementation MarkerEventsViewController {
  GMSMapView *_mapView;
  GMSMarker *_melbourneMarker;
  BOOL _rotating;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
                                                          longitude:144.966085
                                                               zoom:4];
  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
  sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  sydneyMarker.map = _mapView;

  _melbourneMarker = [[GMSMarker alloc] init];
  _melbourneMarker.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  _melbourneMarker.map = _mapView;

  _mapView.delegate = self;
  self.view = _mapView;
}

#pragma mark - GMSMapViewDelegate

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  if (marker == _melbourneMarker) {
    return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon"]];
  }

  return nil;
}

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
  GMSCameraPosition *camera = [[GMSCameraPosition alloc] initWithTarget:marker.position
                                                                   zoom:8
                                                                bearing:50
                                                           viewingAngle:60];
  // Animate to the marker
  [CATransaction begin];
  [CATransaction setAnimationDuration:3.f];  // 3 second animation
  [CATransaction setCompletionBlock:^{
    if (_rotating) {  // Animation was interrupted by orientation change.
      [CATransaction
          setDisableActions:true];  // Disable animation to avoid interruption from rotation.
      [_mapView animateToCameraPosition:camera];
    }
  }];

  [mapView animateToCameraPosition:camera];
  [CATransaction commit];

  // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to fire. Also check
  // that the marker isn't already selected so that the InfoWindow doesn't close.
  if (marker == _melbourneMarker && mapView.selectedMarker != _melbourneMarker) {
    return NO;
  }

  // The Tap has been handled so return YES
  return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  _rotating = true;
  [coordinator
      animateAlongsideTransition:nil
                      completion:^(
                          id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
                        _rotating = false;
                      }];
  [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end
      

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

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

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

    সুইফট

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

    অবজেক্টিভ-সি

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

    সুইফট

    static let apiKey = "YOUR_API_KEY"

    অবজেক্টিভ-সি

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

    সুইফট

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

    অবজেক্টিভ-সি

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

শুরু করুন

নমুনা কোডটি চেষ্টা করার আগে, আপনাকে অবশ্যই আপনার ডেভেলপমেন্ট পরিবেশ কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS কোড নমুনার জন্য Maps SDK দেখুন।

কোডটি দেখুন

সুইফট

import GoogleMaps
import UIKit

final class MarkerEventsViewController: UIViewController {

  private lazy var mapView: GMSMapView = {
    let camera = GMSCameraPosition(latitude: -37.81969, longitude: 144.966085, zoom: 4)
    return GMSMapView(frame: .zero, camera: camera)
  }()

  private var melbourneMarker = GMSMarker(
    position: CLLocationCoordinate2D(latitude: -37.81969, longitude: 144.966085))

  override func loadView() {
    let sydneyMarker = GMSMarker(
      position: CLLocationCoordinate2D(latitude: -33.8683, longitude: 151.2086))
    sydneyMarker.map = mapView
    melbourneMarker.map = mapView
    mapView.delegate = self
    view = mapView
  }
}

extension MarkerEventsViewController: GMSMapViewDelegate {
  func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    if marker == melbourneMarker {
      return UIImageView(image: UIImage(named: "Icon"))
    }
    return nil
  }

  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    // Animate to the marker
    CATransaction.begin()
    CATransaction.setAnimationDuration(3)
    let camera = GMSCameraPosition(target: marker.position, zoom: 8, bearing: 50, viewingAngle: 60)
    mapView.animate(to: camera)
    CATransaction.commit()

    // Melbourne marker has a InfoWindow so return false to allow markerInfoWindow to
    // fire. Also check that the marker isn't already selected so that the InfoWindow
    // doesn't close.
    if marker == melbourneMarker && mapView.selectedMarker != melbourneMarker {
      return false
    }
    return true
  }
}
      

অবজেক্টিভ-সি

#import "GoogleMapsDemos/Samples/MarkerEventsViewController.h"

#import <QuartzCore/QuartzCore.h>

#import <GoogleMaps/GoogleMaps.h>

@implementation MarkerEventsViewController {
  GMSMapView *_mapView;
  GMSMarker *_melbourneMarker;
  BOOL _rotating;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
                                                          longitude:144.966085
                                                               zoom:4];
  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
  sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  sydneyMarker.map = _mapView;

  _melbourneMarker = [[GMSMarker alloc] init];
  _melbourneMarker.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  _melbourneMarker.map = _mapView;

  _mapView.delegate = self;
  self.view = _mapView;
}

#pragma mark - GMSMapViewDelegate

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  if (marker == _melbourneMarker) {
    return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon"]];
  }

  return nil;
}

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
  GMSCameraPosition *camera = [[GMSCameraPosition alloc] initWithTarget:marker.position
                                                                   zoom:8
                                                                bearing:50
                                                           viewingAngle:60];
  // Animate to the marker
  [CATransaction begin];
  [CATransaction setAnimationDuration:3.f];  // 3 second animation
  [CATransaction setCompletionBlock:^{
    if (_rotating) {  // Animation was interrupted by orientation change.
      [CATransaction
          setDisableActions:true];  // Disable animation to avoid interruption from rotation.
      [_mapView animateToCameraPosition:camera];
    }
  }];

  [mapView animateToCameraPosition:camera];
  [CATransaction commit];

  // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to fire. Also check
  // that the marker isn't already selected so that the InfoWindow doesn't close.
  if (marker == _melbourneMarker && mapView.selectedMarker != _melbourneMarker) {
    return NO;
  }

  // The Tap has been handled so return YES
  return YES;
}

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  _rotating = true;
  [coordinator
      animateAlongsideTransition:nil
                      completion:^(
                          id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
                        _rotating = false;
                      }];
  [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

@end
      

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

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

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

    সুইফট

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

    অবজেক্টিভ-সি

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

    সুইফট

    static let apiKey = "YOUR_API_KEY"

    অবজেক্টিভ-সি

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

    সুইফট

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

    অবজেক্টিভ-সি

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