শুরু করুন
আপনি নমুনা কোড চেষ্টা করার আগে, আপনি আপনার উন্নয়ন পরিবেশ কনফিগার করতে হবে. আরও তথ্যের জন্য, iOS কোড নমুনার জন্য মানচিত্র 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 ইনস্টল এবং চেষ্টা করতে এই ধাপগুলি অনুসরণ করুন।
- স্থানীয় ডিরেক্টরিতে নমুনা সংগ্রহস্থল ক্লোন করতে
git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git
চালান। একটি টার্মিনাল উইন্ডো খুলুন, যে ডিরেক্টরিতে আপনি নমুনা ফাইলগুলি ক্লোন করেছেন সেখানে নেভিগেট করুন এবং GoogleMaps ডিরেক্টরিতে ড্রিল ডাউন করুন:
cd maps-sdk-for-ios-samples-main/GoogleMaps-Swift
pod install
open GoogleMapsSwiftDemos.xcworkspace
cd maps-sdk-for-ios-samples-main/GoogleMaps
pod install
open GoogleMapsDemos.xcworkspace
- Xcode-এ, বর্তমান স্কিমের সাথে অ্যাপটি তৈরি করতে কম্পাইল বোতাম টিপুন। বিল্ডটি একটি ত্রুটি তৈরি করে, আপনাকে সুইফটের জন্য
SDKConstants.swift
ফাইলে অথবা Objective-C-এর জন্যSDKDemoAPIKey.h
ফাইলে আপনার API কী লিখতে অনুরোধ করে। - আপনার যদি এখনও একটি API কী না থাকে, তাহলে Google ক্লাউড কনসোলে একটি প্রকল্প সেট আপ করতে নির্দেশাবলী অনুসরণ করুন এবং একটি API কী পান৷ ক্লাউড কনসোলে কী কনফিগার করার সময়, শুধুমাত্র আপনার অ্যাপ কী ব্যবহার করতে পারে তা নিশ্চিত করতে আপনি নমুনা অ্যাপের বান্ডেল শনাক্তকারীর কী সীমাবদ্ধ করতে পারেন। SDK স্যাম্পল অ্যাপের ডিফল্ট বান্ডেল আইডেন্টিফায়ার হল
com.example.GoogleMapsDemos
। - উদ্দেশ্য-C-এর জন্য Swift বা
SDKDemoAPIKey.h
ফাইলের জন্যSDKConstants.swift
ফাইল সম্পাদনা করুন এবংapiKey
বাkAPIKey
ধ্রুবকের সংজ্ঞাতে আপনার API কী পেস্ট করুন। যেমন:static let apiKey = "
YOUR_API_KEY "static NSString *const kAPIKey = @"
YOUR_API_KEY "; -
SDKConstants.swift
ফাইল (Swift) বাSDKDemoAPIKey.h
ফাইলে (উদ্দেশ্য-সি), নিম্নলিখিত লাইনটি সরান, কারণ এটি ব্যবহারকারী-সংজ্ঞায়িত সমস্যা নিবন্ধন করতে ব্যবহৃত হয়:#error (Register for API Key and insert here. Then delete this line.)
#error Register for API Key and insert here.
- নির্মাণ এবং প্রকল্প চালানো. iOS সিমুলেটর উইন্ডোটি প্রদর্শিত হবে, ম্যাপ SDK ডেমোগুলির একটি তালিকা দেখাচ্ছে৷
- iOS এর জন্য Maps SDK-এর একটি বৈশিষ্ট্য নিয়ে পরীক্ষা করার জন্য প্রদর্শিত বিকল্পগুলির মধ্যে একটি বেছে নিন।
- GoogleMapsDemos কে আপনার অবস্থান অ্যাক্সেস করার অনুমতি দেওয়ার জন্য অনুরোধ করা হলে, অনুমতি দিন নির্বাচন করুন।