1

iPhoneアプリからユーザーの現在地を取得したい。アプリに国名、緯度、経度情報などのユーザーの現在地を表示したい。また、グーグルマップにも場所を表示したいです。私もグーグル検索を試しましたが、正確な答えを得ることができません。CLLocationManager場所を追跡するためにアプリで使用する情報を取得しました。これはどのように使用しますか?AppleDocumentsからサンプルアプリを1つダウンロードしました。リンクは次のとおりです:https ://developer.apple.com/library/ios/#samplecode/LocateMe/Introduction/Intro.html

これについて私を助けてくれませんか?前もって感謝します。

4

4 に答える 4

1

これはそれのほとんどを行う必要があります。

http://www.highoncoding.com/Articles/804_Introduction_to_MapKit_Framework_for_iPhone_Development.aspx

MKReverseGeocoderを使用する必要がある場所に関する情報を取得するには

https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40008323

于 2012-02-20T07:12:00.130 に答える
1

1)CLLocationManager場所を追跡するためにアプリで使用する情報を取得しました。これはどのように使用しますか?

.hファイル内

#include <CoreLocation/CLLocationManagerDelegate.h>
#include <CoreLocation/CLError.h>
#include <CoreLocation/CLLocation.h>
#include <CoreLocation/CLLocationManager.h>

CLLocationManager   * myLocationManager;

CLLocation          * myLocation;

.mファイル内:-

    -(void)findMyCurrentLocation
    {           

    self.myLocationManager = [[[CLLocationManager alloc] init] autorelease];
    [[self myLocationManager] setDelegate:self ];
    [myLocationManager startUpdatingLocation];

    double latitude=34.052234;
    double longitude=-118.243685;

    CLLocation *defaultLocation =[[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
    [self setMyLocation:defaultLocation];
    [defaultLocation release];

    if( [CLLocationManager locationServicesEnabled] )
    {   
        NSLog(@"Location Services Enabled....");
        locationServicesEnabled=TRUE;
        UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:@"Information" 
                                                         message:@"Fetching your current location." 
                                                        delegate:self 
                                               cancelButtonTitle:@"OK" 
                                               otherButtonTitles:nil ];
        [alert release];
    }
    else
    {   
        NSLog( @"Location Services Are Not Enabled...." );
        locationServicesEnabled=FALSE;
        UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:@"Information" 
                                                         message:@"Location service is not enable. Please enable it from settings." 
                                                        delegate:self 
                                               cancelButtonTitle:@"OK" 
                                               otherButtonTitles:nil ];
        [alert release];
     }

        }

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
      [self setMyLocation:newLocation];

    NSString *tempLat = [ NSString stringWithFormat:@"%3.6f" , (newLocation.coordinate.latitude) ];
    NSString *tempLong= [ NSString stringWithFormat:@"%3.6f" , (newLocation.coordinate.longitude)];

    appDelegate.curlat = tempLat;
    appDelegate.curlong = tempLong;
   }

     - (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error
     {
    printf("\nerror");
    UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:@"Error" 
                                                     message:@"Error while getting your current location." 
                                                    delegate:self 
                                           cancelButtonTitle:@"OK" 
                                           otherButtonTitles:nil ];

    [alert release];
     }

2)。アプリに国名情報など、ユーザーの現在地を表示したい。

このために、Googleの逆ジオコーディングまたはMKReverseGeocoderを使用できます

于 2012-02-20T07:17:57.620 に答える
0

まず、のインスタンスを作成しますMKMapView

ユーザーの緯度と経度を取得するには

あなたの中でviewDidLoad

[yourMapView setShowsUserLocation:YES];

CLLocationCoordinate2D userCoord;

userCoord.latitude=map_view.userLocation.coordinate.latitude;
userCoord.longitude=map_view.userLocation.coordinate.longitude;

//NSLogging these on simulator will give you Cupertino or whatever location you set in location simulation.

また、国名については、リバースジオコーディングが必要になります。ここでクラスリファレンスを確認できます。

https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40008323

また

MKReverseGeoCodingが複雑になりすぎる場合は、Yahooのリバースジオコーダーを使用できます

http://where.yahooapis.com/geocode?q=%f,%f&gflags=R&appid=yourAppId、これらの2%fはとになりuserCoord.longitudeますuserCoord.latitude

于 2012-02-20T07:19:07.087 に答える
0

はい、CLGeoCoderを使用できます。ただし、CLGeaCoderは、インドなどの他の国の米国以外では正確な位置情報を提供しません。したがって、Googleの逆ジオコーディングSVGeoCoderを使用することをお勧めします。SVGeoCoderには、goolePlaceAPIを使用して場所を取得するための優れた実装があります。

于 2013-10-22T09:09:57.597 に答える