I am making iPhone application in which i am using UIMapKit. I have a static pointer (Arrow) in the middle of screen of iPhone and behind that Pointer i am using iOS maps in which user interaction is enable , means user can move the map can zoom in or zoom out the map.
My task is to get the longitude and latitude of that location which comes under my Screen Pointer(Arrow)
Can anyone help me how can i do achieve this. I have very good command on UIMap i just need a idea
You can get middle point of screen using :
CGPoint screenCenterPoint = self.view.center;
and then convert it to coordinates using :
CLLocationCoordinate2D mapCenterPoint = [self.view convertPoint:screenCenterPoint toCoordinateFromView:self.view];
If you use Google maps then you can use this ,too :
CLLocationCoordinate2D mapCenterPoint = [self.mapView.projection coordinateForPoint: screenCenterPoint];
To learn more look at GMSProjection and GMSMapView.
The necessary functionality is built in to MapView.
CLLocationCoordinate2D pinCoordinate = [self.pickupLocationView convertPoint:CGPointMake(self.pickupLocationView.frame.size.width / 2, self.pickupLocationView.frame.size.height) toCoordinateFromView:self.view];
This is UIKit as the poster requested. I believe Akash's solution would work if the question was about Google's map.
Related
I'm trying to retrieve the mapView current zoom level in google maps using Swift. The documentation states that it should be mapview.camera.zoom but Xcode states that there is no such method.
let camera = self.mapView.camera.zoom
error I receive
"Value of type '(GMSCoordinateBounds, UIEdgeInsets) -> GMSCameraPosition?' has no member 'zoom'"
You can get Zoom level in this way...
let zoom = self.mapView.camera.zoom
I am showing a map view using MapKit framework in my iPhone application. I am also showing the particular friends list Pin point in map view based on the location they are. I would like to enhance now to showing the road map direction from my location to a particular selected friend location. I know the lat and long for both source and destination, but i have draw route line in road direction, it should be road direction. Could someone help me on this?
Thank you!
MapKit does not expose a means of performing driving directions. So, it's not as simple as asking the map to display a course from location A to location B. You have two options:
1) Integrate with Google's API to get the driving directions, and overlay your own lines onto the MapKit map.
or
2) Simply direct your users out of app and delegate this functionality to the built in Map app.
I have no experience with the former, but the later is very easy. Simply:
CLLocationCoordinate2D location = [[map userLocation] location].coordinate;
double currentLat = location.latitude;
double currentLong = location.longitude;
NSString *googleUrl = [[NSString alloc] initWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", currentLat, currentLong, item.latitude, item.longitude];
NSLog(#"%#", googleUrl);
[[UIApplication sharedApplication] openURL:[[NSURL alloc] initWithString:googleUrl]];
Actually there is no api supported by iPhone sdk to draw route on map. There a repo on github which is using google maps api to draw route on map by using map overlay. It has some limitation but you can take help from this repo - https://github.com/kishikawakatsumi/MapKit-Route-Directions
There are few apps like Strava which records users movements using GPS. It also measures the elevation of the road on which they travelled.
I would like to know how can we measure elevation of the road using iPhone SDK?
Please let me know.
Use the Google Elevation API
Example here
Then use a JSON parser to retrieve the values
CoreLocation is what you want to use (although it is generally quite inaccurate I've found)
first import the core location framework in the .h:
#import <CoreLocation/CoreLocation.h>
followed by in the .m:
- (void)locationUpdate:(CLLocation *)location {
altitudeLabel.text = [NSString stringWithFormat:#"Altitude - %f", [location altitude]];
}
This is given in height from sea level
I am using the route-me files found at https://github.com/route-me/route-me to build a offline map application for iPhones.
I have the map working offline and also successfully implemented "current location" button that will show the users location on the map with a marker.
Now, I want to be able to let the users be able to drop "pins" on the map so that users can get the coordinates of the "pins" that user just dropped on the map. (separate from the current location)
I have tried to look for tutorials and other helpful documents on Google but all the information that I've found are using the MapKit lib and framework
If any of you are expert on route-me and using RMMapView to make offline maps, it would be awesome if you guys can help me out.
Thanks
For droping pins on RMMapview , this is required snippet of code used in - (void)viewDidLoad after creating RMMapview
RMMarkerManager *markerManager = [[[RMMarkerManager alloc] initWithContents: mapView]autorelease];
RMMarker *marker = [[RMMarker alloc]initWithUIImage:[UIImage imageNamed:#"marker-blue.png"] anchorPoint:CGPointMake(0.5, 1.0)];
[marker setTextForegroundColor:[UIColor blueColor]];
[markerManager addMarker:marker AtLatLong:(CLLocationCoordinate2D){40.988,23.098}];
[marker release];
I am using map functionality in my iphone app. I m showing stores for users current location on map.
Whenever user scrolls the map he needs to be shown stores of new location. eg. suppose user at
New York at first app will show New York stores but when he scrolls map to Texas then app should fire web service request for Texas location. My problem is
1) if web service request goes at each map scroll, app may crash or wait each time for response for new set of stores. (for this i m going to put some hardcoded radius to send request) So how to handle it proper way.
2) I want to know distance between two location so that i can send request to server only if the distance between 2 locations is greater than some specific value.
I am using map view delegates for above functionality. Please suggest me some proper way to handle it.
Thanks
Well to find the distance between 2 points i use
CLLocation *location1 = [[CLLocation alloc]initWithLatitude:[[dict valueForKey:#"lat"] doubleValue] longitude:[[dict valueForKey:#"lon"]doubleValue]];
float distance =[mUserCurrentLocation distanceFromLocation:location1]/1000;
float distanceinMeters=[mUserCurrentLocation distanceFromLocation:location1]; NSString *distancestr= [NSString stringWithFormat:#"%.2f KM",distance];
See If this can help you.