0

我为我正在开发的 iOS 应用程序创建了一个自定义地图 (jpg)。我在滚动视图中显示了大图像。

我已经有了图像所有四个角的纬度/经度,但我不确定如何转换已知位置,以便我可以在地图的某些位置绘制标签。标签位置基于纬度/经度,因此我需要一种将经度转换为 ax/y 坐标的方法,以在应用程序的图像上显示对象。

我已经查找了这方面的信息,但我发现的所有内容都更多地涉及获取知道的纬度/经度,而不是在应用程序中实现它。

(地图是德克萨斯州大小的区域)

将不胜感激任何指导

谢谢

4

1 回答 1

0

After reading your questions a couple of times, I still do not know what you are trying to do. But here is some tips for converting

say your jpg image has the (lat,lng) of (a,b) to (c,d) and pixel of (width,height)

so to get (lat,lng) from (x,y) you use

lat = a + x/width*(c-a);
lng = b + y/height*(d-b);

Now make sure you are using the same coordinate system. If not, say your pixel starts from lower left instead of top left, then just invert it.

lat = a + x/width*(c-a);
lng = b + (height - y)/height*(d-b);

Same goes for converting x and y from lat and lng. Just reverse the formula above. Now you need to look up stuff from Google using their reverse geocoding API. Unless you prefer something else, here is some snippet:

NSString *urlStr = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true", lat, lng];
NSData *dataFromServer = [NSData dataWithContentsOfURL: [NSURL URLWithString:urlStr]];

dataFromServer contains JSON infomation about the thing you are trying to look up. Parse it however you need to.

Is this what you are looking for?

于 2012-08-27T20:47:27.880 回答