শুরু করুন
স্যাম্পেল কোড ব্যবহার করে দেখার আগে, আপনাকে ডেভেলপমেন্ট এনভায়রনমেন্ট কনফিগার করতে হবে। আরও তথ্যের জন্য, iOS-এর জন্য Maps SDK কোড স্যাম্পেল দেখুন।
কোড দেখুন
Swift
import GoogleMaps import UIKit class GestureControlViewController: UIViewController { private let holderHeight: CGFloat = 60 private let zoomLabelInset: CGFloat = 16 private lazy var mapView: GMSMapView = { let camera = GMSCameraPosition(latitude: -25.5605, longitude: 133.605097, zoom: 3) return GMSMapView(frame: .zero, camera: camera) }() private lazy var zoomSwitch: UISwitch = UISwitch(frame: .zero) override func viewDidLoad() { super.viewDidLoad() view.addSubview(mapView) let holder = UIView(frame: .zero) holder.backgroundColor = UIColor(white: 1, alpha: 0.8) view.addSubview(holder) let zoomLabel = UILabel(frame: .zero) zoomLabel.text = "Zoom gestures" zoomLabel.font = .boldSystemFont(ofSize: 18) holder.addSubview(zoomLabel) // Control zooming. holder.addSubview(zoomSwitch) zoomSwitch.addTarget(self, action: #selector(toggleZoom), for: .valueChanged) zoomSwitch.isOn = true [mapView, holder, zoomLabel, zoomSwitch].forEach({ $0.translatesAutoresizingMaskIntoConstraints = false }) NSLayoutConstraint.activate([ mapView.leftAnchor.constraint(equalTo: view.leftAnchor), mapView.rightAnchor.constraint(equalTo: view.rightAnchor), mapView.topAnchor.constraint(equalTo: view.topAnchor), mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor), holder.heightAnchor.constraint(equalToConstant: holderHeight), holder.centerXAnchor.constraint(equalTo: view.centerXAnchor), holder.widthAnchor.constraint(equalTo: view.widthAnchor), zoomLabel.leftAnchor.constraint(equalTo: holder.leftAnchor, constant: zoomLabelInset), zoomLabel.centerYAnchor.constraint(equalTo: holder.centerYAnchor), zoomSwitch.rightAnchor.constraint(equalTo: holder.rightAnchor, constant: -zoomLabelInset), zoomSwitch.centerYAnchor.constraint( equalTo: holder.centerYAnchor), ]) NSLayoutConstraint.activate([ holder.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor) ]) } @objc func toggleZoom() { mapView.settings.zoomGestures = zoomSwitch.isOn } }
Objective-C
#import "GoogleMapsDemos/Samples/GestureControlViewController.h" #import <GoogleMaps/GoogleMaps.h> @implementation GestureControlViewController { GMSMapView *_mapView; UISwitch *_zoomSwitch; } - (void)viewDidLoad { [super viewDidLoad]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-25.5605 longitude:133.605097 zoom:3]; _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _mapView.accessibilityIdentifier = @"gestureControlDemoMapView"; self.view = [[UIView alloc] initWithFrame:CGRectZero]; [self.view addSubview:_mapView]; UIView *holder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 59)]; holder.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; holder.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.8f]; [self.view addSubview:holder]; // Zoom label. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 200, 29)]; label.text = @"Zooming?"; label.font = [UIFont boldSystemFontOfSize:18.0f]; label.textAlignment = NSTextAlignmentLeft; label.backgroundColor = [UIColor clearColor]; label.layer.shadowColor = [[UIColor whiteColor] CGColor]; label.layer.shadowOffset = CGSizeMake(0.0f, 1.0f); label.layer.shadowOpacity = 1.0f; label.layer.shadowRadius = 0.0f; [holder addSubview:label]; // Control zooming. _zoomSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(-90, 16, 0, 0)]; _zoomSwitch.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; [_zoomSwitch addTarget:self action:@selector(didChangeZoomSwitch) forControlEvents:UIControlEventValueChanged]; _zoomSwitch.on = YES; [holder addSubview:_zoomSwitch]; } - (void)didChangeZoomSwitch { _mapView.settings.zoomGestures = _zoomSwitch.isOn; } @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ফাইল অথবাSDKDemoAPIKey.hObjective-C-এর জন্য ফাইল এডিট করুন এবং আপনার 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-কে আপনার লোকেশন অ্যাক্সেস করার অনুমতি দিতে বলা হলে, অনুমতি দিন বিকল্পটি বেছে নিন।