শুরু করুন
স্যাম্পেল কোড ব্যবহার করে দেখার আগে, আপনাকে ডেভেলপমেন্ট এনভায়রনমেন্ট কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS-এর জন্য Maps SDK কোড স্যাম্পেল দেখুন।
কোড দেখুন
Swift
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 } }
Objective-C
#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 স্যাম্পেল অ্যাপ ইনস্টল ও ব্যবহার করে দেখতে এইসব ধাপ অনুসরণ করুন।
- লোকাল ডিরেক্টরিতে স্যাম্পেল রিপোজিটরি ক্লোন করতে
git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.gitরান করুন। টার্মিনাল উইন্ডো খুলে, যে ডিরেক্টরিতে স্যাম্পেল ফাইল ক্লোন করেছেন সেখানে নেভিগেট করুন এবং GoogleMaps ডিরেক্টরিতে ড্রিল ডাউন করুন:
Swift
cd maps-sdk-for-ios-samples/GoogleMaps-Swift
open GoogleMapsSwiftXCFrameworkDemos.xcodeprojObjective-C
cd maps-sdk-for-ios-samples-main/GoogleMaps
open GoogleMapsDemos.xcodeproj- Xcode প্রোজেক্টে, ফাইল > প্যাকেজ ডিপেন্ডেন্সি যোগ করুন বিকল্পে যান।
URL হিসেবে
https://github.com/googlemaps/ios-maps-sdkলিখুন, প্যাকেজটি নিয়ে আসার জন্য Enter প্রেস করুন এবং প্যাকেজ যোগ করুন বিকল্পে ক্লিক করুন। - Xcode-এ, বর্তমান স্কিম সহ
অ্যাপ তৈরি করতে
কম্পাইল বোতাম প্রেস করুন। বিল্ডে কোনও সমস্যা হলে, আপনাকে Swift-এর জন্য
SDKConstants.swiftফাইলে অথবা Objective-C-এর জন্যSDKDemoAPIKey.hফাইলে API key লিখতে বলা হবে। - iOS-এর জন্য Maps SDK চালু আছে এমন প্রোজেক্ট থেকে API কী পান।
- Swift-এর জন্য
SDKConstants.swiftফাইল অথবা Objective-C-এর জন্যSDKDemoAPIKey.hফাইল এডিট করুন এবং আপনার API কীapiKeyঅথবাkAPIKeyকনস্ট্যান্টের সংজ্ঞায় পেস্ট করুন। যেমন:Swift
static let apiKey = "YOUR_API_KEY"Objective-C
static NSString *const kAPIKey = @"YOUR_API_KEY";
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.
- প্রোজেক্ট তৈরি করে রান করুন। iOS সিমুলেটর উইন্ডো দেখা যাবে, যেখানে Maps SDK ডেমো-এর তালিকা দেখানো হবে।
- iOS-এর জন্য Maps SDK-এর কোনও ফিচার নিয়ে পরীক্ষা করতে, দেখানো বিকল্পগুলির মধ্যে থেকে একটি বেছে নিন।
- GoogleMapsDemos-কে আপনার লোকেশন অ্যাক্সেস করার অনুমতি দিতে বলা হলে, অনুমতি দিন বিকল্পটি বেছে নিন।