2010-12-17 71 views
0

任何人都可以告訴我如何獲取所有經緯度值之間的位置...... ??? 作爲實現的一部分,我希望在起始端點之間具有所有的Lat,Long值來繪製路徑。獲取位置之間的所有座標iphone地圖套件

在此先感謝...

+0

首先,房間分配一個緩衝區aleph_0座標對... – 2010-12-17 20:09:22

回答

0

「全部」是什麼意思?由於經緯度對是雙打的,所以你說的是無限多的點數。

如果你想在兩點之間畫一條線,你可以使用CAShapeLayer在地圖上畫一條線來連接它們。

然而,「路線」一詞隱含着你想知道沿着一條路行駛的點。還有,你真的在​​問什麼?人們可以開車的路線?步行?乘公交車? MapKit本身並不能幫你完成路由,你必須看看其他第三方框架。

+0

由於該鏈接解釋如何得出一個地圖上的路線,我猜你真的想要一個路由引擎 - 你將不得不看像一個像CloudMade SDK:http://developers.cloudmade.com/projects/show/routing-http-api – 2010-12-17 22:00:01

+0

Waah ... !!!這太棒了 ..!!!!我只是快速瀏覽一下它......我應該能夠完成任務。萬分感謝...!!!! – bp581 2010-12-18 00:56:30

3

找到點很簡單,不需要任何聰明的三角。請注意,如果點之間的距離需要特定的數量 - 比如說每100米 - 則需要三角法。不過,我們會做簡單的版本。

基本上你可以計算緯度和經度之間的差異,決定你想要多少點(如上所述,「全部」是無限數),用距離除以點數,然後迭代通過他們。 (注:我沒有測試此代碼,但你應該能明白我的意思。)

// Making my own names for your start and stop coordinate, use your own 
CLLocationCoordinate2D startPoint; // Your starting latitude and longitude 
CLLocationCoordinate2D stopPoint; // Ending latitude and longitude 

CLLocationCoordinate2D newPoint; // A newly-created point along the line 

double latitudeModifier; // Distance to add/subtract to each latitude point 
double longitudeModifier; // Distance to add/subtract to each longitude point 

int numberOfPoints = 100; // The number of points you want between the two points 

// Determine the distance between the lats and divide by numberOfPoints 
latitudeModifier = (startPoint.latitude - endPoint.latitude)/numbernumberOfPoints; 
// Same with lons 
longitudeModifier = (startPoint.longitude - endPoint.longitude)/numbernumberOfPoints; 

// Loop through the points 
for (int i = 0; i < numberOfPoints; i++) { 
    newPoint.latitude = startPoint.latitude + (latitudeModifier * i); 
    newPoint.longitude = startPoint.longitude + (longitudeModifier * i); 

    // Do something with your newPoint here 

} 
+0

感謝您的詳細回覆。代碼工作得很好,以獲得所需的值。但不幸的是,它並沒有達到我想要達到的目標。 生成的點將在起點和終點之間畫出一條直線。在示例spitzkoff.com/craig/?p=65中,繪製了曲線,因爲所有曲線位置的lat值都是可用的。任何想法如何繪製曲線/路線圖......。非常感謝你幫助我解決這個問題的努力...... !!!! – bp581 2010-12-17 22:10:49

+0

啊,以爲你是指直線。您可以通過Google地圖API獲取實際的道路路線。您可以將它發送到您的出發地和目的地,並且會逐步向您發送完整路線,同時爲每個停靠點(以及彎曲道路等)以及駕駛或步行方向提供經/緯度對。 http://code.google.com/apis/maps/documentation/directions/ – 2010-12-18 03:58:16

+0

很棒.. !!!非常感謝 ..!!!!這工作太.. ..! – bp581 2010-12-18 17:28:41