Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c MKMapVIew存在问题,我的Pin点显示方向不正确(我使用的是MKMapVIew的指南针模式)_Objective C_Google Maps_Mkmapview_Compass Geolocation - Fatal编程技术网

Objective c MKMapVIew存在问题,我的Pin点显示方向不正确(我使用的是MKMapVIew的指南针模式)

Objective c MKMapVIew存在问题,我的Pin点显示方向不正确(我使用的是MKMapVIew的指南针模式),objective-c,google-maps,mkmapview,compass-geolocation,Objective C,Google Maps,Mkmapview,Compass Geolocation,我正在开发一个iPhone应用程序,可以与地图一起使用。在这个应用程序中,我需要根据纬度和经度显示一些停车位(地址)。在这一点上,我成功地完成了,但我想显示相对于用户方向(SE、SW、NE、NW)的引脚点。我试着在MKMapview中使用指南针模式,但它显示了错误方向的针点 我的代码中有错误还是web服务的错误?我将用户位置LAT和LONG以及用户方向传递给web服务 我现在给你看屏幕截图 - (void)updateHeading:(CLHeading *) newHeading { NSLo

我正在开发一个iPhone应用程序,可以与地图一起使用。在这个应用程序中,我需要根据纬度和经度显示一些停车位(地址)。在这一点上,我成功地完成了,但我想显示相对于用户方向(SE、SW、NE、NW)的引脚点。我试着在MKMapview中使用指南针模式,但它显示了错误方向的针点

我的代码中有错误还是web服务的错误?我将用户位置LAT和LONG以及用户方向传递给web服务

我现在给你看屏幕截图

- (void)updateHeading:(CLHeading *) newHeading {
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);
double rotation = newHeading.magneticHeading * 3.14159 / 180;
NSLog(@"rotation ========> %f",rotation);
[mapView setTransform:CGAffineTransformMakeRotation(rotation)];

[[mapView annotations] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    MKAnnotationView * view = [mapView viewForAnnotation:obj];

    [view setTransform:CGAffineTransformMakeRotation(rotation)];
}];
//NSLog(@"newlocation course : %f",mapView.userLocation.location.course);
float mHeading = newHeading.magneticHeading;
NSLog(@"mHeading %f",mHeading);
//direction is a string
if(mHeading > 0 && mHeading <90) {
    // north east
    NSLog(@"~~~~~~~~~~~~~~~~north east");
    direction = @"North East";
}
else if(mHeading > 90 && mHeading < 180)  {
    // south east
    NSLog(@"~~~~~~~~~~~~~~~~south east");
    direction = @"South East";
}
else if(mHeading > 180 && mHeading < 270) {
    // south west
    NSLog(@"~~~~~~~~~~~~~~~~south west");
    direction = @"South West";
}
else if(mHeading > 270 && mHeading < 360) {
    // north west
    NSLog(@"~~~~~~~~~~~~~~~~north west");
    direction = @"North West";
}

if([changedDirction isEqualToString:direction])
{
    NSLog(@"called nothing/changedDirction.....");
}
else
{
  NSURL *url = [NSURL URLWithString:@"http://www.charlottecentercity.org/services/nearbylocations.php"];
  NSLog(@"url is---%@",url);
  directionsRequest = [[ASIFormDataRequest alloc] initWithURL:url];
 [directionsRequest setPostValue:[NSString stringWithFormat:@"%f", appdelegate.currentLocation.latitude] forKey:@"lat"];
 [directionsRequest setPostValue:[NSString stringWithFormat:@"%f", appdelegate.currentLocation.longitude] forKey:@"long"];
 directionLabel.text = direction;
[directionsRequest setPostValue:direction forKey:@"direction"];
[directionsRequest setPostValue:self.mapID forKey:@"id"];
 directionsRequest.delegate = self;
[directionsRequest startAsynchronous];
 changedDirction = direction;
 } }


-(void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"request finished is calling....");
if ([venuDescArray count]>0)
{
    [venuDescArray removeAllObjects]; 

}

NSError *error = [request error];
NSLog(@"error is%@",error);
if (!error) 
{
    NSString *responseString = [request responseString];
    NSMutableArray *array = [responseString JSONValue];
    NSLog(@"response array for category wise pin--%@",array);
    for (int i = 0; i<[array count]; i++) 
    {
        NSMutableDictionary *theDict = [array objectAtIndex:i];
        PlacesObject *aVenue = [[PlacesObject alloc] init];
        aVenue.venueDetailsplaceID = [theDict objectForKey:@"placeid"];
        aVenue.venueDetailsname = [theDict objectForKey:@"name"];
        aVenue.venueDetailsaddress = [theDict objectForKey:@"address"];
        aVenue.venueDetailslatitude = [theDict objectForKey:@"latitude"];
        aVenue.venueDetailslongitude = [theDict objectForKey:@"longitude"];

        [venuDescArray addObject:aVenue];
    }

    NSLog(@"venuDescArray count is---%d",[venuDescArray count]);
}
[self setLocations]; }

-(void)setLocations {

[annotaionsArray11 removeAllObjects];
[mapView removeAnnotations:mapView.annotations];
 NSLog(@"annotations removed....");

self.mapView.mapType = MKMapTypeStandard;
self.mapView.delegate = self;

MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];

float lati_new =appdelegate.currentLocation.latitude;//35.227087;
float longi_new =appdelegate.currentLocation.longitude;//-80.843127; 

myAnnotation.annType=@"Current";
myAnnotation.title1 =@"Current our Location";

myAnnotation.latitude=[NSNumber numberWithFloat:lati_new];
myAnnotation.longitude =[NSNumber numberWithFloat:longi_new];
NSLog(@"myAnnotation.latitude/float---%@",myAnnotation.latitude);
NSLog(@"myAnnotation.longitude/float---%@",myAnnotation.longitude);

[annotaionsArray11 addObject:myAnnotation];

[myAnnotation setButtonTag:0];

 NSLog(@"self.venuDescArray count:%d",[self.venuDescArray count]);

PlacesObject *placesObj=[[PlacesObject alloc] init];

for (int i=0; i<[self.venuDescArray count]; i++) 
{
    placesObj=[self.venuDescArray objectAtIndex:i];

    MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];

    myAnnotation.annType=@"Points";

    myAnnotation.title1 =placesObj.venueDetailsname;
    NSLog(@"myAnnotation.title1's is---%@",myAnnotation.title1);
    myAnnotation.subTitle =placesObj.venueDetailsaddress;
    NSLog(@"myAnnotation.subTitle is---%@",myAnnotation.subTitle);
    myAnnotation.latitude =[NSNumber numberWithFloat:[placesObj.venueDetailslatitude floatValue]];
    NSLog(@"myAnnotation.latitudes is ----%@",myAnnotation.latitude);
    myAnnotation.longitude =[NSNumber numberWithFloat:[placesObj.venueDetailslongitude floatValue]];
    NSLog(@"myAnnotation.longitude is ----%@",myAnnotation.longitude);
    [annotaionsArray11 addObject:myAnnotation];
    NSLog(@"annotaionsArray11---%d",[annotaionsArray11 count]);

    [myAnnotation setButtonTag:i];
}

NSLog(@"annotaionsArray count after adding all locations..%d",[annotaionsArray11 count]);
 [mapView addAnnotations:annotaionsArray11];  }

-(void)更新标题:(CLHeading*)新标题{
NSLog(@“新磁航向:%f”,新航向。磁航向);
NSLog(@“新的真实标题:%f”,newHeading.trueHeading);
双旋转=新航向。磁航向*3.14159/180;
NSLog(@“旋转=====>%f”,旋转);
[mapView setTransform:CGAffineTransformMakeRotation(旋转)];
[[mapView注释]enumerateObjectsUsingBlock:^(id obj,整数idx,布尔*停止){
MKAnnotationView*视图=[mapView视图用于注释:obj];
[视图集变换:CGAffineTransformMakeRotation(旋转)];
}];
//NSLog(@“新位置课程:%f”,mapView.userLocation.location.course);
浮动mHeading=newHeading.magneticeHeading;
NSLog(@“mHeading%f”,mHeading);
//方向是一根弦
如果(mHeading>0&&mHeading 90&&mHeading<180){
//东南部
NSLog(@“~~~~~~~~~~~~~~~~~~东南”);
方向=@“东南”;
}
否则,如果(mHeading>180&&mHeading<270){
//西南部
NSLog(@“~~~~~~~~~~~~~~~~~~~西南”);
方向=@“西南”;
}
否则如果(mHeading>270&&mHeading<360){
//西北部
NSLog(@“~~~~~~~~~~~~~~~~~~~西北”);
方向=@“西北”;
}
if([changedDirction isEqualToString:方向])
{
NSLog(@“调用nothing/changedDirction…”);
}
其他的
{
NSURL*url=[NSURL URLWithString:@”http://www.charlottecentercity.org/services/nearbylocations.php"];
NSLog(@“url为---%@”,url);
DirectionRequest=[[ASIFormDataRequest alloc]initWithURL:url];
[DirectionRequest setPostValue:[NSString stringWithFormat:@“%f”,appdelegate.currentLocation.latitude]forKey:@“lat”];
[DirectionRequest setPostValue:[NSString stringWithFormat:@“%f”,appdelegate.currentLocation.longitude]forKey:@“long”];
directionLabel.text=方向;
[DirectionRequest setPostValue:direction forKey:@“direction”];
[DirectionRequest setPostValue:self.mapID-forKey:@“id”];
directionrequest.delegate=self;
[方向请求启动同步];
改变方向=方向;
} }
-(void)requestFinished:(ASIHTTPRequest*)请求{
NSLog(@“请求完成正在调用…”);
如果([venuDescArray计数]>0)
{
[venuDescArray removeAllObjects];
}
n错误*错误=[请求错误];
NSLog(@“错误为%@”,错误);
如果(!错误)
{
NSString*responseString=[request responseString];
NSMutableArray*数组=[responseString JSONValue];
NSLog(@“分类引脚响应数组--%@”,数组);

对于(int i=0;i,由于这个问题在某种程度上是特定的,并且这里并没有显示所有代码,所以我只能尝试从当前可用的信息中推断。 您希望根据用户的标题显示四个不同停车位置组中的一个,但更改标题时,注释不会更改

基于web服务返回正确结果的假设,问题可能是由您的使用方式引起的

MKAnnotationView * view = [mapView viewForAnnotation:obj];

请检查您是否在代码中使用了重用标识符。

“正确方向”你的意思是你想让图钉始终指向北方,即使地图旋转,使西部位于屏幕顶部?如果是这样,我会反对。我还没有在任何其他地图应用程序中看到这样的情况,你的用户可能会认为图钉都掉了是很奇怪的。你确定你得到了正确的回应吗网络服务?