I am trying to display some location in MKMapView. While loading the mapViewController, I am getting the following error message in console.
__GEORegisterNetworkDefaults_block_invoke_0: Could not connect to geod on com.apple.geod.defaults
I am using xcode 4.3 and iOS 5.1 for my application.
I am using the following code to show the address:
- (void) showAddress
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.2;
span.longitudeDelta = 0.2;
CLLocationCoordinate2D location = [self addressLocation];
region.span = span;
region.center = location;
}
And for getting the address location from following code.
-(CLLocationCoordinate2D) addressLocation
{
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",
[#"cupertino" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSError *err;
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:&err];
NSArray *listItems = [locationString componentsSeparatedByString:#","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:#"200"])
{
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
When I google about the mapkit tutorials then I found the above code from http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial
Does anyone know why I am getting the above error?
Have you told XCode that your app requires access to location information? I think it's 'privileges' or something similar in the project config.
Related
This should be Los Angeles:
double latitude = 34.05;
double longitude = 118.25;
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latitude, longitude);
NSString *desc = #"hey there";
NSString *address = #"some address";
CLLocationCoordinate2D coordinate;
coordinate.latitude = location.latitude;
coordinate.longitude = location.longitude;
MyLocation *annotation = [[MyLocation alloc] initWithName:desc address:address coordinate:coordinate]; //implements <MKAnnotation>
NSArray *annotations = #[annotation];
[self.mapView showAnnotations:annotations animated:YES];
However this annotation ends up in Eastern China. What am I missing in the conversion?
I think you want -118.25 degrees for Los Angles.
I am wondering how I might be able to get the placemark's zip code in iOS. Any tips or suggestions will be deeply appreciated. Here is the code I have so far, I am able to get the city.
- (void)recenterMapToPlacemark:(CLPlacemark *)placemark {
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.02;
span.longitudeDelta = 0.02;
region.span = span;
region.center = placemark.location.coordinate;
NSString *city = [placemark locality];
}
Check the documentation here:
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLPlacemark_class/Reference/Reference.html#//apple_ref/occ/instp/CLPlacemark/postalCode
It is the postalCode property you are looking for.
So in your case it is:
NSString *zipCode = placemark.postalCode;
I am using Google Maps SDK in iOS app.I am stuck at plotting multiple pins on map.This is how I am trying to plot the pins.And I used the exact same approach to show multiple pins using MapKit which worked fine.But no success with google Maps.
-(void)plotMembersOnMap
{
for (NSMutableDictionary *obj in self.jsonDictionary)
{
membersDict = [obj objectForKey:#"members"];
NSLog(#"Count member %d",[membersDict count]); // shows count
for (NSDictionary *obj in membersDict)
{
CLLocationCoordinate2D center;
NSString *latitudeString = [obj objectForKey:#"lat"];
NSString *longitudeString = [obj objectForKey:#"lng"];
double latitude = [latitudeString doubleValue];
double longitude = [longitudeString doubleValue];
center.latitude =latitude;
center.longitude = longitude;
NSString *userName = [obj objectForKey:#"pseudo"];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.map = mapView_;
marker.position = CLLocationCoordinate2DMake(center.latitude, center.longitude);
customGoogleCallout.callOutTitleLabel.text = #"Member";
customGoogleCallout.callOutUserName.text = userName;
marker.icon = [UIImage imageNamed:#"marker_membre.png"];
}
}
}
just try to add lat and lon to an array then supply the marker.position.
have some loop for i and position is object at index[i].
this might help...
CLLocationCoordinate2D center = { [[obj objectForKey:#"lat"] floatValue] , [[obj objectForKey:#"lon"] floatValue] };
GMSMarker *marker = [GMSMarker markerWithPosition:center];
Try this ,
NSArray *latitudeString = [obj objectForKey:#"lat"];
NSArray *longitudeString = [obj objectForKey:#"lng"];
Instead of
NSString *latitudeString = [obj objectForKey:#"lat"];
NSString *longitudeString = [obj objectForKey:#"lng"];
Maybe because it's plotting the latest coordinate you assign to center. You should make new instance so the previous value will not replaced.
I have this code for my iOS app:
NSString *location = [[NSString alloc] initWithFormat:#"%#, %#", [self.campus campusStreetAddress], [self.campus campusCityStateZip]];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKCoordinateRegion region = self.campusMap.region;
region.center = placemark.region.center; //DEPRECATED iOS 7
region.span.longitudeDelta /= 1500;
region.span.latitudeDelta /= 1500;
[self.campusMap setRegion:region animated:NO];
[self.campusMap addAnnotation:placemark];
}
}
];
But, when I upgraded my app to iOS 7, placemark.region.center is deprecated. Is there a replacement I should use? Is this even a proper method to creating a map in a view?
Thanks!!
Try this:
region.center = [(CLCircularRegion *)placemark.region center];
if you just want the center of the region you can use :
region.center = placemark.location.coordinate
Combination of Heesien's and other answers and a bit of experimenting.
- (void)centerMapAroundPlacemark:(MKPlacemark *)placemark
{
CLRegion *region = placemark.region;
if ([region isKindOfClass:[CLCircularRegion class]])
{
[self centerMapAroundCircularRegion:(CLCircularRegion *)region
centerCoodinate:placemark.location.coordinate];
}
else
{
[self centerMapAroundCoorinate:placemark.location.coordinate];
}
}
- (void)centerMapAroundCircularRegion:(CLCircularRegion *)circularRegion
{
MKCoordinateRegion coordinateRegion =
MKCoordinateRegionMakeWithDistance(circularRegion.center,
circularRegion.radius,
circularRegion.radius);
[self.mapView setRegion:coordinateRegion animated:YES];
}
- (void)centerMapAroundCircularRegion:(CLCircularRegion *)circularRegion
centerCoodinate:(CLLocationCoordinate2D)centerCoodinate
{
// Only user the radius of region for an appropriate zoom level.
// The center of the region is not accurate.
// To see this search for 'Bath, UK'
MKCoordinateRegion coordinateRegion =
MKCoordinateRegionMakeWithDistance(centerCoodinate,
circularRegion.radius,
circularRegion.radius);
[self.mapView setRegion:coordinateRegion animated:YES];
}
The code should do an adress search. The line CLLocationCoordinate2D location2 = [self adressLocation isn't working. It's saying "Invalid Initializer". What could be wrong?
-(IBAction) search {
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.4;
span.longitudeDelta = 0.4;
CLLocationCoordinate2D location2 = [self adressLocation];
region.span = span;
region.center = location2;
Mark adr = [[Mark alloc] initWithCoordinate:location2];
[mapView addAnnotation:adr];
}
-(CLLocationCoordinate2D) adressLocation {
NSString * urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",[suchFeld.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString * locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:&fileError];
NSArray * listItems = [locationString componentsSeparatedByString:#","];
double latitude2 = 0.0;
double longitude2 = 0.0;
if ([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:#"200"])
{
latitude2 = [[listItems objectAtIndex:2] doubleValue];
longitude2 = [[listItems objectAtIndex:3] doubleValue];
} else {
// error
CLLocationCoordinate2D location2;
location2.latitude = latitude2;
location2.longitude = longitude2;
return location2;
}
The adressLocation method is probably not declared in the .h file and since the method is defined after the code calling it, the compiler gives that error. Add this to the .h file:
-(CLLocationCoordinate2D) adressLocation;
Some separate issues:
In the search method, you have Mark adr = [[Mark alloc]....
This should be Mark *adr = [[Mark alloc]... (note asterisk).
Also in the search method, you need to do [adr release]; after the addAnnotation line.
Finally, adressLocation does not return a value in all cases.
It only does a return in the else-part. It needs to return a value in the if-part also.