问题
I have created a table in database named UserJourneyLocation which consist of columns LocationID, Latitude, Longitude.
The latitude and longitude values are stored in SQLite database. I want to fetch these latitude and longitude values that are there and display them on map and draw route that displays starting location and destination location.
回答1:
try this:-
NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
It opens your google map pointing out your source location and destination location with route. The parameter it requires are the latitude and longitude of both source and destination location .Pass your latitude and longitude values which you are fetching form database.
回答2:
the next code is iOS 4.0+
CLLocationCoordinate2D points[2]; // how many points you have saved
points[0] = CLLocationCoordinate2DMake(52.3, 9.7); // you can for loop initializing, i made it so for simplicity :)
points[1] = CLLocationCoordinate2DMake(52.37, 9.74);
MKPolyline* ret = [MKPolyline polylineWithCoordinates:points count:2];
and then you can add it as an overlay to you mapView
来源:https://stackoverflow.com/questions/6275140/drawing-routes-with-the-help-of-latitude-and-longitude-values-saved-in-database