Using MapKit in iOS 6, how am I'm supposed to get nearby locations without having their specific coordinates? I'm also unsure if it's still possible...err...allowed...to use Google Maps API to accomplish this goal, as this is the only way I can think of to do this. I know everything is still in beta, but I've still found no information anywhere about this topic, on forums, in Apple's new MapKit Documentation, anywhere. All I want to do is perform a search for locations (let's say, parks, for example) within 'x' miles of the user's location.
It seems that since Apple has developed their own Maps application, they should have a way to accomplish this using MapKit or Core Location...right?
Try with this code. This may help to you.
URLManager *urlmanager = [[URLManager alloc] init];
urlmanager.delegate = self;
urlmanager.responseType = JSON_TYPE;
urlmanager.commandName = #"Search";
NSString *locationString = [NSString stringWithFormat:#"%f,%f",latitude,longitude];
//Location where you want to search
NSString *key = #"AIzaSyCNRpero6aM451X0IfgFHAd-Y3eJUssqoa8`enter code here`0E";
//This is the secret key which you will get from the Google API Console when you register your app.
NSString *radiuos = #"15000";
//This is the area within which you want to search
NSString *keyword = #"Hotel";//Search keyword you want to search
NSMutableDictionary *arguments = [[NSMutableDictionary alloc] init]; // zero argument
[arguments setValue:key forKey:#"key"];
[arguments setValue:locationString forKey:#"location"];
[arguments setValue:radiuos forKey:#"radius"];
[arguments setValue:#"true" forKey:#"sensor"];
[arguments setValue:keyword forKey:#"keyword"];
NSLog(#"Arguments are %#",arguments);
[urlmanager urlCallGetMethod:[NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json"] withParameters:arguments];
Related
i am making an application which has a feature that allows users to create location based notifications to turn the application on/off when they arrive/leave a certain location.
Reminders are created (as indicated by the first picture), but are not triggered upon arriving/leaving.
If on the other hand the user click on the reminder, it kind of adds the address (shown on picture number 2) and is from there on triggered
I was wondering if there is a way to make the Reminder app recognize the address or any other suggestion, that might help me in solving this peculiar problem.
Thank you in advance,
BR,
Rok
The code that i use is:
EKReminder *reminder = [EKReminder reminderWithEventStore:_eventStore];
reminder.calendar = [_eventStore defaultCalendarForNewReminders];
EKStructuredLocation *location;
NSError *error = nil;
EKAlarm *alarm = [[EKAlarm alloc]init];
reminder.title = #"Turn off Test App";
location = [EKStructuredLocation locationWithTitle:self.addressTextField.text];
[self.addressTextField resignFirstResponder];
alarm.proximity = EKAlarmProximityEnter;
alarm.structuredLocation = location;
[reminder addAlarm:alarm];
[_eventStore saveReminder:reminder commit:YES error:&error];
The problem is that you are failing to set your EKStructuredLocation's geolocation and radius. All it has is a title. That isn't enough to tell the alarm where on earth it is supposed to be!
Example:
location.geoLocation =
[[CLLocation alloc] initWithLatitude:latit longitude:longit];
location.radius = 10*1000; // metres
See CLLocationManager -startMonitoringForRegion:, and the CLRegion class reference.
im developing an iphone app using yahoo weather service ( i have a key ).
i have 2 question :
can i use it in my app for commercial use ( like posting my app in appstore for free or no )
why the xml and json result are different :
http://weather.yahooapis.com/forecastrss?w=29330057&u=c
and
http://weather.yahooapis.com/forecastjson?w=29330057&u=c
there is any thing to do to much ( the first have the wanted location )?
thank you.
I suspect this is an issue with XML namespaces. Depending on the framework used and the actual full XML you'd have to access the elements by their namespace. You might want to switch to another, DOM-based framework (not using NSXMLParser), for example GDataXMLNode by Google. In a DOM-based framework you can access the individual nodes in a tree-like structure instead of building one on your own.
There are plenty of examples for this on the net, for example Building an RSS reader or How to read and write XML documents with GDataXML. But to give a quick example how this might look:
NSError *error = nil;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];
if (doc == nil) { return nil; }
NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
NSArray *lists = [doc nodesForXPath:#"/result/list" error:nil];
if ([lists count] > 0)
{
for (GDataXMLNode *list in lists) {
int listid = [self integerInNode:list forXPath:#"listid"];
NSString *listname = [self stringInNode:list forXPath:#"name"];
[result setValue:[NSNumber numberWithInt:listid] forKey:listname];
}
}
[doc release];
return [result autorelease];
Yes, Yahoo! let you use their APIs under a fair-use policy, even commercially. Don’t be an ass and give them enough props though, e.g. their icon or logo with a link to their website.
I don’t think that it’s important to know why there are differences in both output formats. Use what is better / easier for you. Personally I prefer using JSON and Apple’s NSJSONSerialization class.
Is it possible to use the mapkit in the iphone sdk to calculate driving distance between two addresses ?
How about using the Core Location framework:
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
You'll need the latitude/longitudes for both addresses.
Edit: Deprecated in iOS 3.2. Use the distanceFromLocation: method instead.
With iOS7 you get full directions within the API
Take a look at this tutorial Tutorial.
No but if you have the longitude/latitude then it is fairly easy to calculate the distance. It is the mathematical distance between those points of course. Not the actual driving or walking distance that is based on an actual route.
In my applications I used MKDirections to get driving (walking) distance between two location.
CLLocationCoordinate2D startCoordinates = YOUR_START_COORDINATES;
CLLocationCoordinate2D endCoordinates = YOUR_END_COORDINATES;
MKPlacemark *startPoint = [[MKPlacemark alloc] initWithCoordinate:startCoordinates];
MKPlacemark *endPoint = [[MKPlacemark alloc] initWithCoordinate:endCoordinates];
MKMapItem *startItem = [[MKMapItem alloc] initWithPlacemark:startPoint];
MKMapItem *endItem = [[MKMapItem alloc] initWithPlacemark:endPoint];
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = startItem;
request.destination = endItem;
request.transportType = MKDirectionsTransportTypeAutomobile; //here you can choose a transport type you need
MKDirections *direction = [[MKDirections alloc] initWithRequest:request];
[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
for (MKRoute *route in response.routes) {
NSLog(#"Distance : %f", route.distance);
}
}
}];
if you have you location as an address, so you can use the method of CLGeocoder, which will give you latitude and longitude of your address
- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
If you compare a driving distance result using MKDirections with the one using Google Maps, you will see that they differ. I was searching regarding this matter and came across the following link http://www.macworld.co.uk/review/reference-education/apple-maps-vs-google-maps-3464377/
Even though Apple have been improving their map service, they still concede in accuracy to Google (IMO), at least in a question regarding the driving distance.
So if accuracy is not highly important in your case, so you can follow along with Apple. Otherwise I would recommend checking Google API.
I have been trying to get this to work for about three solid days and get my mind around it. Can someone advise.
I have built the basics and they all work great but when I try to do that extra bit I cannot get my head around it.
I am trying to build a table of technical terms, from a plist. This is an indexed and sections table by the alphabet.
This works fine but when I then try to add the next level for each term's definition in a new viewcontroller I can't seem to get the code or the plist structure right.
At the moment I have created two plists. One with a dictionary of the alphabet in 26 arrays, within each array is a series of technical terms. All this works great.
Then I've created another plist of definitions as an array of dictionaries, one for each word/definition pair. I'm expecting to be passing the #"word" key from the view controller to the detailviewcontroller then picking up the #"definition". I don't know whether this is right or wrong(?)
My code shows the technical term table great but when a row is selected it crashes. I know it's to do with the code for passing the detailviewcontroller's reference so the detailview can pick up the definition - but I've no idea how to solve it. I've posted parts of my code here for someone to look at help. Any ideas?
NSString *wordPath = [[NSBundle mainBundle] pathForResource:#"newsortedglossary" ofType:#"plist"];
NSDictionary *wordDict = [[NSDictionary alloc] initWithContentsOfFile:wordPath];
self.words = wordDict;
[words release];
NSArray *wordArray = [[words allKeys] sortedArrayUsingSelector:#selector(compare:)];
self.wordKeys = wordArray;
NSString *definitionPath = [[NSBundle mainBundle] pathForResource:#"newnewdefinitionglossary" ofType:#"plist"];
NSDictionary *definitionDict = [[NSDictionary alloc] initWithContentsOfFile:definitionPath];
self.definitions = definitionDict;
[definitions release];
didSelectRow here.........
GlossaryDetailViewController *glossaryDetailViewController = [[GlossaryDetailViewController alloc]
initWithNibName:#"GlossaryDetailView" bundle:nil];
NSLog(#"did select-2"); // CRASHES HERE with NSDictionary may not respond to objectAtIndex
glossaryDetailViewController.definition = [self.words objectAtIndex:indexPath.row];
NSLog(#"did select-3");
[self.navigationController pushViewController:glossaryDetailViewController animated:YES];
NSLog(#"did select-4");
[glossaryDetailViewController release];
detailViewController here.......
- (void)viewDidAppear:(BOOL)animated {
NSLog(#"didappear");
self.glossaryWordDefinition.text = [definition objectForKey:#"definition"];
It seems that you are trying to access the members of dictionary by using an index, instead of using a key to lookup the associated value.
In your didSelectRow you probably want this:
glossaryDetailViewController.definition = [self.wordKeys objectAtIndex:indexPath.row];
The difference is that now you are trying access the members of an array with the index.
I need to find the driving distance between 2 locations. I do not need to display the directions in a map, just need to calculate the distance, which I need to use in my application.
Does MapKit allow this? Is there an alternative that can be used?
I am able to get forward geo-coding using CloudMade, but there doesn't seem to be an option to obtain driving distance.
Appreciate any help.
CloudMade also offers driving directions. If you are only interested in the distance, simply ignore the instructions.
An API-Call looks like this:
http://navigation.cloudmade.com/YOUR-API-KEY-GOES-HERE/api/0.3/47.25976,9.58423,47.26117,9.59882/car/shortest.js
and the JSON includes
....
route_summary: {
total_distance: Distance in meters,...
Source
Found this in Google Groups, is that helpful?
http://groups.google.com/group/google-maps-api/msg/4dc2fad4f74e3314?pli=1
In my applications I used MKDirections to get driving (walking) distance between two location.
CLLocationCoordinate2D startCoordinates = YOUR_START_COORDINATES;
CLLocationCoordinate2D endCoordinates = YOUR_END_COORDINATES;
MKPlacemark *startPoint = [[MKPlacemark alloc] initWithCoordinate:startCoordinates];
MKPlacemark *endPoint = [[MKPlacemark alloc] initWithCoordinate:endCoordinates];
MKMapItem *startItem = [[MKMapItem alloc] initWithPlacemark:startPoint];
MKMapItem *endItem = [[MKMapItem alloc] initWithPlacemark:endPoint];
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = startItem;
request.destination = endItem;
request.transportType = MKDirectionsTransportTypeAutomobile; //here you can choose a transport type you need
MKDirections *direction = [[MKDirections alloc] initWithRequest:request];
[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
for (MKRoute *route in response.routes) {
NSLog(#"Distance : %f", route.distance);
}
}
}];
if you have you location as an address, so you can use the method of CLGeocoder, which will give you latitude and longitude of your address
- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
If you compare a driving distance result using MKDirections with the one using Google Maps, you will see that they differ. I was searching regarding this matter and came across the following link http://www.macworld.co.uk/review/reference-education/apple-maps-vs-google-maps-3464377/
Even though Apple have been improving their map service, they still concede in accuracy to Google (IMO), at least in a question regarding the driving distance. So if accuracy is not highly important in your case, so you can follow along with Apple. Otherwise I would recommend checking Google API.