我在谷歌地图上使用GMSPolyline来显示两点之间的最短路径。此地图未正确显示用户的当前位置。
这是我的代码。让我知道我可以在我的代码中进行的更正。提前谢谢。
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
/////// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 0.5)
{
/////// Update your marker on your map using location.coordinate.latitude
//and location.coordinate.longitude);
NSLog(@"event time=%@",eventDate);
#pragma mark start Point of Polyline Drow
///////////////Logitude 23.03 apvathe darek point tyathe start thay etle polyline Drow thay/////
if (location.coordinate.longitude==23.03)
{
[locationManager stopUpdatingLocation];
}
[mypath addObject:[NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude]];
GMSMutablePath *path1 = [GMSMutablePath path];
for (int i=0; i<mypath.count; i++)
{
//NSString *str1=mypath[i];
NSArray* foo = [mypath[i] componentsSeparatedByString: @","];
NSString* lat = [foo objectAtIndex: 0];
NSString* longi = [foo objectAtIndex: 1];
[path1 addCoordinate:CLLocationCoordinate2DMake([lat floatValue], [longi floatValue])];
}
GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path1];
rectangle.map = mapView_;
marker.position = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);
marker.title = @"Gurukul Road,Ahmedabad";
marker.snippet = @"Gujarat";
marker.map = mapView_;
}
}
答案 0 :(得分:0)
你必须在纬度和经度的情况下更精确地使用%f并且根据纬度和经度的值使用此代码不准确...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
strForCurrentLongitude= [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
strForCurrentLatitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
}
在此行中取Double值而不是float。
[path1 addCoordinate:CLLocationCoordinate2DMake([lat floatValue], [longi floatValue])];