How to achieve density/heat map effect in iOS (iPh

2019-06-03 14:47发布

问题:

http://www.econguru.com/heat-map-of-worldwide-gdp-ppp-per-capita-2008/

This is CIA world Factbook map, each country has different color depth based on their GDP number. High GDP country has deeper color.

Right now, I am considering to develop such effect into my iPhone/iPad map app. I may want to use the apple map (probably not google map since iOS 6 has its own map), but I am not sure how to get such effect based on the country the user visited.

For example, the user visited US the most, then the map shows deeper color in US.

I haven't seen such effect in iPhone app yet. Any suggestion would be appreciated!

回答1:

This should be doable using MapKit and overlays. You would need to construct an overlay for each area of the heat map and then set the color according to the data. I suspect the hardest part is going to be getting the geographic data you need to construct the paths for each region. AFAICT, there's no -pathForState: or -pathForCountry: type of functions in MapKit, so you're going to need to find another source for that information. But in terms of drawing overlays, it's all there in MapKit. Check out this sample code.

EDIT:

This question has some pointers on where to get that data.



回答2:

You can get the coordinates ready to go in json format from the D3 project on github: https://github.com/latentflip/d3/blob/master/data/world-countries.json

You can download this json, use NSJsonSerialization with the file to load the json into a Dictionary or an array, and then build your overlays from there.

One other thing: you aren't technically after a heat map; what you're afer is more of a "thematic" map.



回答3:

Try the LFHeatMap class. Seems to be what you're looking for. https://github.com/gpolak/LFHeatMap