এই ভিডিওটি মার্কারগুলির বিকল্প হিসাবে হিটম্যাপের ব্যবহার নিয়ে আলোচনা করে, যখন আপনার ডেটার জন্য মানচিত্রে প্রচুর পরিমাণে ডেটা পয়েন্টের প্রয়োজন হয়৷
হিটম্যাপগুলি দর্শকদের জন্য একটি মানচিত্রে ডেটা পয়েন্টগুলির বিতরণ এবং আপেক্ষিক তীব্রতা বোঝা সহজ করে তোলে৷ প্রতিটি অবস্থানে একটি মার্কার স্থাপন করার পরিবর্তে, হিটম্যাপগুলি ডেটা বিতরণের প্রতিনিধিত্ব করতে রঙ ব্যবহার করে।
নীচের উদাহরণে, লাল রঙ অস্ট্রেলিয়ার ভিক্টোরিয়াতে পুলিশ স্টেশনগুলির উচ্চ ঘনত্বের এলাকাগুলিকে প্রতিনিধিত্ব করে।
মানচিত্রে একটি হিটম্যাপ
আপনি যদি এখনও লাইব্রেরি সেট আপ না করে থাকেন, তাহলে এই পৃষ্ঠার বাকি অংশ পড়ার আগে সেটআপ গাইড অনুসরণ করুন।
একটি সাধারণ হিটম্যাপ যোগ করা হচ্ছে
আপনার মানচিত্রে একটি হিটম্যাপ যোগ করতে, আপনার আগ্রহের প্রতিটি অবস্থানের জন্য স্থানাঙ্ক সমন্বিত একটি ডেটাসেটের প্রয়োজন হবে। প্রথমে, একটি GMUHeatmapTileLayer দৃষ্টান্ত তৈরি করুন, একটি GMSMapViewmap সম্পত্তি সেট করুন। হিটম্যাপের সাথে কাজ করার আগে বেস ম্যাপ লোড হয়েছে তা নিশ্চিত করতে আপনার অ্যাপের viewDidLoad() ফাংশনে এটি করুন। তারপর GMUHeatmapTileLayer ইনস্ট্যান্সে GMUWeightedLatLng বস্তুর একটি সংগ্রহ পাস করুন।
ইউটিলিটি GMUHeatmapTileLayer ক্লাস সরবরাহ করে, যা GMUWeightedLatLng বস্তুর সংগ্রহ গ্রহণ করে। এটি সরবরাহ করা ব্যাসার্ধ, গ্রেডিয়েন্ট এবং অস্বচ্ছতার বিকল্পগুলির উপর ভিত্তি করে বিভিন্ন জুম স্তরের জন্য টাইল চিত্র তৈরি করে।
আরও বিশদে পদক্ষেপগুলি দেখছি:
একটি GMUHeatmapTileLayer উদাহরণ তৈরি করুন, একটি GMSMapView এ map বৈশিষ্ট্য সেট করুন (এটি আপনার অ্যাপের viewDidLoad() ফাংশনে করুন)।
GMUHeatmapTileLayer উদাহরণে GMUWeightedLatLng বস্তুর একটি সংগ্রহ পাস করুন।
GMUHeatmapTileLayer.map এ কল করুন, ম্যাপ ভিউ পাস করুন।
সুইফট
classHeatmap:UIViewController{privatevarmapView:GMSMapView!privatevarheatmapLayer:GMUHeatmapTileLayer!overridefuncviewDidLoad(){super.viewDidLoad()heatmapLayer=GMUHeatmapTileLayer()heatmapLayer.map=mapView}// ...funcaddHeatmap(){// Get the data: latitude/longitude positions of police stations.guardletpath=Bundle.main.url(forResource:"police_stations",withExtension:"json")else{return}guardletdata=try?Data(contentsOf:path)else{return}guardletjson=try?JSONSerialization.jsonObject(with:data,options:[])else{return}guardletobject=jsonas?[[String:Any]]else{print("Could not read the JSON.")return}varlist=[GMUWeightedLatLng]()foriteminobject{letlat=item["lat"]as!CLLocationDegreesletlng=item["lng"]as!CLLocationDegreesletcoords=GMUWeightedLatLng(coordinate:CLLocationCoordinate2DMake(lat,lng),intensity:1.0)list.append(coords)}// Add the latlngs to the heatmap layer.heatmapLayer.weightedData=list}}
উদ্দেশ্য-C
@implementationHeatmap{GMSMapView*_mapView;GMUHeatmapTileLayer*_heatmapLayer;}-(void)viewDidLoad{[superviewDidLoad];_heatmapLayer=[[GMUHeatmapTileLayeralloc]init];_heatmapLayer.map=_mapView;}// ...-(void)addHeatmap{// Get the data: latitude/longitude positions of police stations.NSURL*path=[NSBundle.mainBundleURLForResource:@"police_stations"withExtension:@"json"];NSData*data=[NSDatadataWithContentsOfURL:path];NSArray*json=[NSJSONSerializationJSONObjectWithData:dataoptions:0error:nil];NSMutableArray<GMUWeightedLatLng*>*list=[[NSMutableArrayalloc]init];[jsonenumerateObjectsUsingBlock:^(id_Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop){NSDictionary*item=(NSDictionary*)obj;CLLocationDegreeslat=[(NSNumber*)[itemvalueForKey:@"lat"]doubleValue];CLLocationDegreeslng=[(NSNumber*)[itemvalueForKey:@"lng"]doubleValue];GMUWeightedLatLng*coords=[[GMUWeightedLatLngalloc]initWithCoordinate:CLLocationCoordinate2DMake(lat,lng)intensity:1.0];[listaddObject:coords];}];// Add the latlngs to the heatmap layer._heatmapLayer.weightedData=list;}@end
এই উদাহরণের জন্য, ডেটা একটি JSON ফাইলে সংরক্ষিত হয়, police_stations.json । এখানে ফাইল থেকে একটি নির্যাস আছে:
হিটম্যাপের বেশ কিছু কাস্টমাইজযোগ্য বৈশিষ্ট্য রয়েছে। আপনি প্রাথমিকভাবে GMUHeatmapTileLayer ইনস্ট্যান্স তৈরি করার সময় বিকল্পগুলি সেট করতে পারেন, বা বিকল্পের জন্য একটি নতুন মান সেট করে যেকোনো সময়।
নিম্নলিখিত বিকল্পগুলি উপলব্ধ:
ব্যাসার্ধ: হিটম্যাপে প্রয়োগ করা গাউসিয়ান ব্লারের আকার, পিক্সেলে প্রকাশ করা হয়। ডিফল্ট হল 20। 10 থেকে 50 এর মধ্যে হতে হবে। ব্যাসার্ধ সেট করতে GMUHeatmapTileLayer.radius ব্যবহার করুন।
গ্রেডিয়েন্ট: রঙের একটি পরিসর যা হিটম্যাপ তার রঙের মানচিত্র তৈরি করতে ব্যবহার করে, সর্বনিম্ন থেকে সর্বোচ্চ তীব্রতা পর্যন্ত। একটি GMUGradient তৈরি করা হয় একটি পূর্ণসংখ্যার অ্যারে ব্যবহার করে যার মধ্যে রয়েছে রং, এবং একটি ফ্লোট অ্যারে প্রতিটি রঙের প্রারম্ভিক বিন্দু নির্দেশ করে, সর্বাধিক তীব্রতার শতাংশ হিসাবে দেওয়া হয় এবং 0 থেকে 1 পর্যন্ত ভগ্নাংশ হিসাবে প্রকাশ করা হয়। আপনাকে একটি একক-রঙের গ্রেডিয়েন্টের জন্য শুধুমাত্র একটি রঙ নির্দিষ্ট করতে হবে, অথবা একটি মাল্টি-রং গ্রেডিয়েন্টের জন্য ন্যূনতম দুটি রঙের জন্য নির্দিষ্ট করতে হবে। রঙের মানচিত্রটি সেই রঙগুলির মধ্যে ইন্টারপোলেশন ব্যবহার করে তৈরি করা হয়। ডিফল্ট গ্রেডিয়েন্টে দুটি রঙ রয়েছে। colorMapSize প্যারামিটার গ্রেডিয়েন্টে ধাপের সংখ্যা নির্ধারণ করে। বড় সংখ্যাগুলি একটি মসৃণ গ্রেডিয়েন্টে পরিণত হবে, যখন ছোট সংখ্যাগুলি একটি কনট্যুর গ্রাফের মতো তীক্ষ্ণ রূপান্তর দেবে। গ্রেডিয়েন্ট সেট করতে GMUHeatmapTileLayer.gradient ব্যবহার করুন।
অপাসিটি: এটি সম্পূর্ণ হিটম্যাপ স্তরের অস্বচ্ছতা, এবং 0 থেকে 1 পর্যন্ত রেঞ্জ৷ ডিফল্ট হল 0.7৷ অস্বচ্ছতার মান সেট করতে GMUHeatmapTileLayer.opacity ব্যবহার করুন।
ইতিমধ্যে সেট করা একটি বিকল্প আপডেট করতে, এই পদক্ষেপগুলি নিন:
পছন্দসই মান বিকল্প আপডেট করুন.
GMUHeatmapTileLayer.clearTileCache() কল করুন।
ডেটাসেট পরিবর্তন করা হচ্ছে
ডেটাসেট পরিবর্তন করতে যার উপর একটি হিটম্যাপ তৈরি করা হয়েছে:
আপনার ডেটা সংগ্রহ আপডেট করুন। GMUWeightedLatLng এর একটি অ্যারে পাস করে GMUHeatmapTileLayer.weightedData ব্যবহার করুন।
GMUHeatmapTileLayer.clearTileCache() কল করুন।
একটি হিটম্যাপ সরানো হচ্ছে
একটি হিটম্যাপ সরাতে, GMUHeatmapTileLayer.map , পাসিং nil কল করুন।
সুইফট
heatmapLayer.map=nil
উদ্দেশ্য-C
_heatmapLayer.map=nil;
ডেমো অ্যাপটি দেখুন
একটি হিটম্যাপ বাস্তবায়নের আরেকটি উদাহরণের জন্য, ডেমো অ্যাপে HeatmapViewController দেখুন যা ইউটিলিটি লাইব্রেরির সাথে পাঠানো হয়। সেটআপ গাইড আপনাকে দেখায় কিভাবে ডেমো অ্যাপ চালাতে হয়।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-09-04 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eHeatmaps visualize the density of data points on a map using color, offering an alternative to markers for large datasets.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGMUHeatmapTileLayer\u003c/code\u003e class is used to create heatmaps, accepting \u003ccode\u003eGMUWeightedLatLng\u003c/code\u003e objects for data points.\u003c/p\u003e\n"],["\u003cp\u003eHeatmaps can be customized by adjusting properties like radius, gradient, and opacity using the \u003ccode\u003eGMUHeatmapTileLayer\u003c/code\u003e instance.\u003c/p\u003e\n"],["\u003cp\u003eTo update the heatmap's data or options, modify the relevant properties and then call \u003ccode\u003eclearTileCache()\u003c/code\u003e to refresh the display.\u003c/p\u003e\n"],["\u003cp\u003eHeatmaps can be removed from the map by setting the \u003ccode\u003emap\u003c/code\u003e property of the \u003ccode\u003eGMUHeatmapTileLayer\u003c/code\u003e to \u003ccode\u003enil\u003c/code\u003e.\u003c/p\u003e\n"]]],["Heatmaps display data density on maps using color, offering an alternative to markers. To add one, create a `GMUHeatmapTileLayer` instance, setting its `map` property to `GMSMapView`. Then, supply `GMUWeightedLatLng` objects representing data coordinates to this instance and call `GMUHeatmapTileLayer.map`. Customize heatmaps by adjusting `radius`, `gradient`, and `opacity` properties. To modify data or settings, update values and call `GMUHeatmapTileLayer.clearTileCache()`. To remove the heatmap, set the `map` property to `nil`.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/heatmap \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/utility/heatmap \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/heatmaplayer \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThis page describes the heatmap utility that's available in the [utility\nlibrary for the\nMaps SDK for iOS](https://github.com/googlemaps/google-maps-ios-utils).\nHeatmaps are useful for representing the distribution and\ndensity of data points on a map.\n\nThis video discusses the use of heatmaps as an alternative to markers, when\nyour data requires a large number of data points on the map. \n\nHeatmaps make it easy for viewers to understand the distribution and relative\nintensity of data points on a map. Rather than placing a marker at each\nlocation, heatmaps use color to represent the distribution of the data.\n\nIn the example below, red represents areas of high concentration of police\nstations in Victoria, Australia.\nA heatmap on a map **Note:** You can set your own colors for the heatmap, using the `gradient` property. See how to [customize](#customize) colors and other properties of your heatmap.\n\nIf you haven't yet set up the library, follow the [setup\nguide](/maps/documentation/ios-sdk/utility/setup) before reading the rest of\nthis page.\n\nAdding a simple heatmap\n\nTo add a heatmap to your map, you will need a dataset consisting of the\ncoordinates for each location of interest. First, create a\n`GMUHeatmapTileLayer` instance, setting the `map` property to a `GMSMapView`.\nDo this in your app's `viewDidLoad()` function, to ensure that the base map is\nloaded before working with the heatmap. Then pass a collection of\n`GMUWeightedLatLng` objects to the `GMUHeatmapTileLayer` instance.\n\nThe utility supplies the `GMUHeatmapTileLayer` class, which accepts a\ncollection of `GMUWeightedLatLng` objects. It creates the tile images for\nvarious zoom levels, based on the radius, gradient and opacity options\nsupplied.\n\nLooking at the steps in more detail:\n\n1. Create a `GMUHeatmapTileLayer` instance, setting the `map` property to a `GMSMapView` (do this in your app's `viewDidLoad()` function).\n2. Pass a collection of `GMUWeightedLatLng` objects to the `GMUHeatmapTileLayer` instance.\n3. Call `GMUHeatmapTileLayer.map`, passing the map view. \n\n Swift \n\n ```swift\n class Heatmap: UIViewController {\n\n private var mapView: GMSMapView!\n private var heatmapLayer: GMUHeatmapTileLayer!\n\n override func viewDidLoad() {\n super.viewDidLoad()\n heatmapLayer = GMUHeatmapTileLayer()\n heatmapLayer.map = mapView\n }\n\n // ...\n\n func addHeatmap() {\n\n // Get the data: latitude/longitude positions of police stations.\n guard let path = Bundle.main.url(forResource: \"police_stations\", withExtension: \"json\") else {\n return\n }\n guard let data = try? Data(contentsOf: path) else {\n return\n }\n guard let json = try? JSONSerialization.jsonObject(with: data, options: []) else {\n return\n }\n guard let object = json as? [[String: Any]] else {\n print(\"Could not read the JSON.\")\n return\n }\n\n var list = [GMUWeightedLatLng]()\n for item in object {\n let lat = item[\"lat\"] as! CLLocationDegrees\n let lng = item[\"lng\"] as! CLLocationDegrees\n let coords = GMUWeightedLatLng(\n coordinate: CLLocationCoordinate2DMake(lat, lng),\n intensity: 1.0\n )\n list.append(coords)\n }\n\n // Add the latlngs to the heatmap layer.\n heatmapLayer.weightedData = list\n }\n }\n \n ```\n\n Objective-C \n\n ```objective-c\n @implementation Heatmap {\n GMSMapView *_mapView;\n GMUHeatmapTileLayer *_heatmapLayer;\n }\n\n - (void)viewDidLoad {\n [super viewDidLoad];\n _heatmapLayer = [[GMUHeatmapTileLayer alloc] init];\n _heatmapLayer.map = _mapView;\n }\n\n // ...\n\n - (void) addHeatmap {\n\n // Get the data: latitude/longitude positions of police stations.\n NSURL *path = [NSBundle.mainBundle URLForResource:@\"police_stations\" withExtension:@\"json\"];\n NSData *data = [NSData dataWithContentsOfURL:path];\n NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];\n\n NSMutableArray\u003cGMUWeightedLatLng *\u003e *list = [[NSMutableArray alloc] init];\n [json enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {\n NSDictionary *item = (NSDictionary *)obj;\n CLLocationDegrees lat = [(NSNumber *) [item valueForKey:@\"lat\"] doubleValue];\n CLLocationDegrees lng = [(NSNumber *) [item valueForKey:@\"lng\"] doubleValue];\n GMUWeightedLatLng *coords = [[GMUWeightedLatLng alloc] initWithCoordinate:CLLocationCoordinate2DMake(lat, lng)\n intensity:1.0];\n [list addObject:coords];\n }];\n\n\n // Add the latlngs to the heatmap layer.\n _heatmapLayer.weightedData = list;\n }\n @end\n \n ```\n\nFor this example, the data is stored in a JSON file, `police_stations.json`.\nHere is an extract from the file: \n\n [\n {\"lat\" : -37.1886, \"lng\" : 145.708 } ,\n {\"lat\" : -37.8361, \"lng\" : 144.845 } ,\n {\"lat\" : -38.4034, \"lng\" : 144.192 } ,\n {\"lat\" : -38.7597, \"lng\" : 143.67 } ,\n {\"lat\" : -36.9672, \"lng\" : 141.083 }\n ]\n\nCustomizing the heatmap\n\nThe heatmap has several customizable properties. You can set the options when\ninitially creating the `GMUHeatmapTileLayer` instance, or at any time by\nsetting a new value for the option.\n\nThe following options are available:\n\n1. **Radius:** The size of the Gaussian blur applied to the heatmap, expressed\n in pixels. The default is 20. Must be between 10 and 50. Use\n `GMUHeatmapTileLayer.radius` to set the radius.\n\n2. **Gradient:** A range of colors that the heatmap uses to generate its color\n map, ranging from lowest to highest intensity. A `GMUGradient` is created using\n an integer array containing the colors, and a float array indicating the\n starting point for each color, given as a percentage of the maximum intensity,\n and expressed as a fraction from 0 to 1. You need to specify only one color for\n a single-colored gradient, or a minimum of two colors for a multi-colored\n gradient. The color map is generated using interpolation between those colors.\n The default gradient has two colors. The `colorMapSize` parameter defines the\n number of steps in the gradient. Larger numbers will result in a smoother\n gradient, while smaller numbers will give sharper transitions similar to a\n contour graph. Use `GMUHeatmapTileLayer.gradient` to set the gradient.\n\n3. **Opacity:** This is the opacity of the entire heatmap layer, and ranges\n from 0 to 1. The default is 0.7. Use `GMUHeatmapTileLayer.opacity` to set the\n opacity value.\n\nFor example, create a `Gradient`:\n\n\nSwift \n\n```swift\nlet gradientColors: [UIColor] = [.green, .red]\nlet gradientStartPoints: [NSNumber] = [0.2, 1.0]\nheatmapLayer.gradient = GMUGradient(\n colors: gradientColors,\n startPoints: gradientStartPoints,\n colorMapSize: 256\n)\n \n```\n\nObjective-C \n\n```objective-c\nNSArray\u003cUIColor *\u003e *gradientColors = @[UIColor.greenColor, UIColor.redColor];\nNSArray\u003cNSNumber *\u003e *gradientStartPoints = @[@0.2, @1.0];\n_heatmapLayer.gradient = [[GMUGradient alloc] initWithColors:gradientColors\n startPoints:gradientStartPoints\n colorMapSize:256];\n \n```\n\n\u003cbr /\u003e\n\nTo change the opacity of an existing heatmap:\n\n\nSwift \n\n```swift\nheatmapLayer.opacity = 0.7\n \n```\n\nObjective-C \n\n```objective-c\n_heatmapLayer.opacity = 0.7;\n \n```\n\n\u003cbr /\u003e\n\nUpdate an existing option\n\nTo update an option that has already been set, take these steps:\n\n1. Update the option to the desired value.\n2. Call `GMUHeatmapTileLayer.clearTileCache()`.\n\nChanging the dataset\n\nTo change the dataset upon which a heatmap is built:\n\n1. Update your data collection. Use `GMUHeatmapTileLayer.weightedData`, passing an array of `GMUWeightedLatLng`.\n2. Call `GMUHeatmapTileLayer.clearTileCache()`.\n\n| **Note:** if you want to add points to the heatmap, or remove points from the heatmap, first update your data collection and then use `GMUHeatmapTileLayer.weightedData`.\n\nRemoving a heatmap\n\nTo remove a heatmap, call `GMUHeatmapTileLayer.map`, passing `nil`.\n\n\nSwift \n\n```swift\nheatmapLayer.map = nil\n \n```\n\nObjective-C \n\n```objective-c\n_heatmapLayer.map = nil;\n \n```\n\n\u003cbr /\u003e\n\nSee the demo app\n\nFor another example of a heatmap implementation, take a look at the\n`HeatmapViewController` in the demo app that ships with the utility library.\nThe [setup guide](/maps/documentation/ios-sdk/utility/setup) shows you how to\nrun the demo app."]]