CLLocationCoordinate2D invalid initializer - iphone

I am using CLLocationCoordinate2D in to assign latitude and longitude like this
CLLocationDegrees latitude = [somelat doubleValue];
CLLocationDegrees longitude = [somelongi doubleValue];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
When i run this code in iPhone simulator its not showing error but wheni run the same application in ios simulator 3.2 that is the iPad simulator its showing me an "Invalid Initializer" error.
How can i resolve this...Please anybody suggest me a solution to this problem
Thanks and regards,
Sankar Chandra Bose

CLLocationCoordinate2DMake is available only on iOS 4.0 and later. Do this rather,
CLLocationCoordinate2D coordinate;
coordinate.longitude = longitude;
coordinate.latitude = latitude;

CLLocationCoordinate2DMake is available only from ios 4.0. Check the reference
CLLocationCoordinate2DMake
Formats a latitude and longitude value
into a coordinate data structure
format.
CLLocationCoordinate2D
> CLLocationCoordinate2DMake(
> CLLocationDegrees latitude,
> CLLocationDegrees longitude)
Parameters
latitude
The latitude for the new coordinate. longitude
The longitude for the new coordinate.
Return Value
A coordinate structure encompassing
the latitude and longitude values.
Availability
Available in iOS 4.0 and later.

Related

Get direction of User by CLLocation

Hi, i am working on GPS ios app.
I want to display user's location on Circle as shown in image.
The user is in center.
I want to display his friend's location on proper direction.
I had already got langitude and latitude of both user .
But how can i get other user's direction?
If can i use Bearing angle?
I get the Distance between two uses by this code
CLLocation *locA = [[CLLocation alloc] initWithLatitude:Latitude longitude:Longitude];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:app.lat longitude:app.lag];
CLLocationDistance distance = [locB distanceFromLocation:locA];
Thanks for Help!!
You can do it using two ways :
1.
CLLocationCoordinate2D start = { c_lat, c_long };
CLLocationCoordinate2D destination = { [[dic valueForKey:#"business_lat"]doubleValue], [[dic valueForKey:#"business_long"]doubleValue] };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&",start.latitude, start.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
2.
Using Google API
In API you just need to pass origin name and destination name
Hope this helped....
This question describing how to compute bearing using the haversine function

Short dictanse from given latitude and longitude iphone

In my application i have array of latitude and longitude with 5-6 places i want to short distance from my current location and show it on my map view for example: i have 3 places location A,B and C so i want to short them according to my current location if location C is near to my current location then first i want to show C location on MAP after that calculate location A and B with location C means which location is near to place C if B is near to place C then show B location on map and at the last show location A
How can we do that ?
To see the distance between two locations
CLLocation *locA = [[CLLocation alloc] initWithLatitude:latA longitude:longA];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:latB longitude:longB];
CLLocation *locC = [[CLLocation alloc] initWithLatitude:latC longitude:longC];
CLLocation *yourLoc = [[CLLocation alloc] initWithLatitude:yourLat longitude:yourLong];
then get the distances between the place and your location
CLLocationDistance distance = [locA distanceFromLocation:yourLoc];
CLLocationDistance distance2 = [locB distanceFromLocation:yourLoc];
CLLocationDistance distance3 = [locC distanceFromLocation:yourLoc];
and finally compare the distances.

Convert CLLocation to CLLocationDegrees

How can I convert CLLocation to CLLocationDegrees, so that I could create CLLocationCoordinate2D structure?
Just get the CLLocationCoordinate2D directly from the coordinate property of CLLocation.
myLocationCoordinate2D = myLocation.coordinate;
Reference Docs
CLLocation.coordinate property will return CLLocationCoordinate2D for you. No need to do any conversions.

Get coordinates by giving name of place in iphone

Is it possible to get coordinates by giving name of a place in iPhone? I don't want to use any Web Service as they have few limitations. Can i do it using iPhone SDK?
Thanks in advance.
As #raj2raaz have mentioned, we can'nt get coordinates by just specify the name of the place, you must have to use web servics in iPhone to get coordinates.
http://iphonesdksnippets.com/post/2010/02/15/Get-Coordinates-from-Address.aspx
The short answer is no, you can't give an address and get the longitude / latitude position. Several people have written libraries that use the different web services, see this answer for details: Forward geocoding from the iPhone .
I know that you said you don't want to use various web services, but, well, you can't get everything for free. Somebody's CPU cycles are going to have to do a search. Most of them seem to me to have terms that are acceptable for most applications.
Yes, it's possible, but you have to do some work. I am currently putting this effort in one of my project. The GeoNames geographical database covers all countries and contains over eight million placenames that are available for download free of charge. I am adding their cites with population over 1,000 3.9M zip file to my project. It's contain long/lat of each city. I am going to parse each city into a custom NSObject and load them into Core Data.
In my project, instead of doing a city name search, I am going to find the closet city to a particular lat/long coordinate. Haversine formula is used to calculate the distance between two points on a sphere. Here are the formula written in Objective-C and Perl.
My current progress of parsing that data can be found here. I still have work to complete.
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:YOUR_LOCATION completionHandler:^(NSArray* placemarks, NSError* error)
{
NSLog(#"completed");
if ( error )
{
NSLog(#"error = %#", error );
}
else
{
//Here you get information about the place in placemarks array
}
}];
you can get the coordinates by calling this method .this method requires the address(name of place).
-(CLLocationCoordinate2D) addressLocation:(NSString *)addrss {
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",
[addrss stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
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];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}

convert nsstring to cllcoordinate

i am working on a application where i am saving the coordinates of a location in database
now i need to use these coordinates and display the location on a map. Can some one please
suggest me how can i change the latitude & longitude stored as NSString to coordinate. I want
to use these coordinates to display an anotation on the map.
Thanks in advance
CLLocationCoordinate2D anyLocation = [[CLLocationCoordinate2D alloc] init];
anyLocation.latitude = [latText doubleValue];
anyLocation.longitude = [lonText doubleValue];
latText and lonText are strings