问题描述
我有一个基于地图的应用程序,使用Google地图的iOS SDK。我需要在核心数据数据库中存储多达数千个项目,并在地图上用标记显示它们。出于性能和可用性的原因,我需要在用户缩小时对这些标记进行聚集,但是我需要确保放置代表性标记,以便用户知道放大到哪里以查看更多详细信息。
I have a map-based application, using Google Maps' iOS SDK. I need to store up to several thousand items in a core data database and display them with markers on the map. For performance and usability reasons, I need to cluster these markers when the user is zoomed out, but I need to make sure to place representative markers so the user knows where to zoom in to see more detail.
我的核心数据模型中的每个条目都存储了纬度/经度双精度值。所以我想到的聚类项目是保持一个单独的实体,我剥离地理坐标的较不重要的部分,并在其中存储一个计数。
Each entry in my core data model has latitude/longitude double values stored. So what I thought of for clustering the items is to keep a separate entity where I strip the less significant parts of the geographic coordinates and store a count in it.
具有lat / lon {44.9382719,-130.20293849}的项目被插入到数据库中,具有lat / lon {44.9,-130.2}的另一个集群对象的count属性将增加。想法是,在低缩放(即缩小),我只查询集群对象,并将它们放在地图上,而不是实际的项目。
So whenever an item with lat/lon {44.9382719, -130.20293849} is inserted in the database, another "cluster" object with lat/lon {44.9, -130.2} has its count property incremented. The idea is that at low zooms (ie. zoomed out), I would only query the cluster objects and place those on the map instead of the actual items.
我的问题是:根据,您不应该抓取 awakeFromInsert
My question is: according to the NSManagedObject reference, you're not supposed to fetch stuff in awakeFromInsert
, so how can I make sure that inserting a managed object of one kind updates the value of a corresponding managed object of another kind?
推荐答案
如何确保插入一种类型的托管对象更新另一种托管对象的值? >
我在Google地图iOS版中搜索了关于Clustering Markers的图书馆三天,最后我最终得到了,它运行良好,非常易于使用和理解。
I have been searching library for Clustering Markers in Google Maps for iOS for three days, and finally I ended up with this https://github.com/googlemaps/google-maps-ios-utils, which is working nicely and very easy to use and understand.
这篇关于在iOS中集中Google地图标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!