Launching Google Maps with "My Location" as the starting point label - ios

i use the following code to launch Google Maps to show step by step navigation from my current location to a specific location:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"comgooglemaps://?daddr=%f,%f&saddr=%f,%f",destLocation.coordinate.latitude, destLocation.coordinate.longitude,_currentLocation.coordinate.latitude,_currentLocation.coordinate.longitude]];
however, when Google Maps app opens, it displays for example "Howard Street" as the starting point label, which is correct, but how can I let Google Maps app displays "My Location" label instead of the street name label as the starting point ?
p.s. the user can display "My Location" label if he/she taps on the coordinates, then choose "My Location" as the starting point from inside Google Maps, but I want this behavior to be done on behalf of the user.

from Google Maps SDK, if I didn't provide the source coordinates, Google Maps will automatically display "My Location" as the starting point label.

Related

how to show Custom user location programmatically

Hey I'm a beginner and learning Ios App development and i want to know that how to set the the user location programmatically like we did here using IDE (Custom Location) :-
I setup everything and location system is working fine in my simulator (fake location) what i have to do if i want to do the same thing programmatically i worked myself and found a little solution but its not helping me out like something is missing here's my code :-
- (IBAction)showMyLocation:(id)sender {
CLLocation *currentLocation=[[CLLocation alloc]initWithLatitude:75.14254 longitude:75.14254];
_map.userLocation.coordinate=currentLocation.coordinate;
_map.showsUserLocation=YES;
}
this code works but let me tell you how
if i set the location in simulator to none nothing happen when i trigger the action.
if i set the location to any of the given option lets just say apple it will show location of the apple and when i trigger the action the location that i give just showed for once like a second and than again the location of the apple is showed.
soo anyone who can help me out will be truly appreciated and my apologies to everyone to whom the question seem inappropriate.
Sometimes the location services on simulator are affected because of API key you are using. Your must have a look of this link firstly and follow the steps in order to implement google map in iOS.
Use following code to get user current location.
CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager requestWhenInUseAuthorization];
Save latitude & longitude accordingly.
float latitude = locationManager.location.coordinate.latitude;
float longitude = locationManager.location.coordinate.longitude;
Now you can navigate user location programatically using this method
- (IBAction)showMyLocation:(id)sender {
CLLocationCoordinate2D centre;
centre.latitude = latitude; // getting latitude
centre.longitude = longitude; // getting longitude
// IF USING MkMapView
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(centre, 200, 200)];
[self.mapView setRegion:adjustedRegion animated:YES];
// IF USING GMSMapView
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
[self.mapView animateToCameraPosition:camera];
}
Note: add these tow keys NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription into your project's info.plist file before see image below.
You can use this AppleScript to open the simulator and set the location automatically:
tell application "Simulator"
activate
end tell
tell application "System Events"
tell process "Simulator"
tell menu bar 1
tell menu bar item "Debug"
tell menu "Debug"
tell menu item "Location"
click
tell menu "Location"
click menu item "Custom Location…"
end tell
end tell
end tell
end tell
end tell
tell window 1
set value of text field 1 to "52,625"
set value of text field 2 to "13,51"
click button "OK"
end tell
end tell
end tell
I used run-applescript to run AppleScript inside my javascript code.
runApplescript('tell application "Simulator" \nactivate\nend tell\ntell application "System Events"\ntell process "Simulator"\ntell menu bar 1\ntell menu bar item "Debug"\ntell menu "Debug"\ntell menu item "Location"\nclick\ntell menu "Location"\nclick menu item "Custom Location…"\nend tell\nend tell\nend tell\nend tell\nend tell\ntell window 1\nset value of text field 1 to "52,625"\nset value of text field 2 to "13,51"\nclick button "OK"\nend tell\nend tell\nend tell')
PS: You need to give permission to terminal. (System Preferences -> Security & Privacy -> Privacy tab -> Select Accessibility on the left menu -> select terminal on the list)

Custom myLocationButton Google maps iOS SKD

Is there one way to customize myLocationButton GoogleMaps ? I want to add my own button with a background image which make the same function as the original Google button
First your Application needs to get current location using CLLocation Manager. If you don't know how, refer to my answer here : For google maps iOS sdk, current location occasionally gets plotted at 0,0
Now for button press action, do this
- (void)locationButtonPressed
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.mapView.myLocation.coordinate.latitude
longitude:self.mapView.myLocation.coordinate.longitude
zoom:self.mapView.camera.zoom];
[self.gMapView animateToCameraPosition:camera];
}
Hope that helps.

How to share start location to destination route

I am developing one application which has functionality like drawing route on map. User needs to start and stop button which indicates that user start drawing route on map with lat long. When user reached his destination and user stop it, I am able to see route from start location to destination location route and I want to share that route with someone through application.
Here is my basic idea of application so any one here please suggest me what to do for that kind of functionality.
As far as I know, direction sharing is already possible when using Google Maps. As given in Get directions and show routes, to send someone directions and a link to the route in Google Maps, follow the steps below:
Open the Google Maps app.
In the bottom right, tap Directions .
Select a route.
In the top right, tap More on three vertical dots.
Tap Share directions.
To help you on the implementation, you can use Maps SDK for iOS - Getting Started and Google Maps URL Scheme for a complete guide on how to work with or to launch Google Maps app for iOS and perform specific functions.
I am doing that thing like this
-(void)drawSenderPath:(CLLocationCoordinate2D)locPolyLine {
[mapView clear]
[pathSender addCoordinate:locPolyLine];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:pathSender];
// Add the polyline to the map.
polyline.strokeColor = AppOrangeColor;
if ([self.homeViewDelegate respondsToSelector:#selector(getPathColor)]) {
polyline.strokeColor = [self.homeViewDelegate getPathColor];
}
polyline.strokeWidth = 3.0f;
polyline.map = mapView;
}

How does WatchKit handle multiple map annotations on the same map?

In WatchKit, the documentation for WKInterfaceMap specify that:
"Tapping the map launches the Maps app on the user’s Apple Watch and
displays the corresponding location.
However: I want to show multiple map annotations on the map - is there a way to specify which map annotation will be displayed in Maps.app when the map is tapped?
There is currently no visibility as to exactly what happens when Apple Watch transitions from a WKInterfaceMap to Apple's native Maps application.
Try the WatchKit Developer Forums, exactly the right place for this question!
Currently in WatchOS 2 (at least), tapping on a WKInterfaceMap will open up the Watch's Maps app with the option the get directions to the location that was at the centre point of your WKInterfaceMap. When viewing these directions to this location it will be marked with a Red Pin annotation.
None of your custom annotations will be displayed in the Watch's Maps app.
You can use following methods to add multiple annotations. As per Apple documentation, currently only 5 annotations can be displayed on watch app's map
addAnnotation:withPinColor
addAnnotation:withImageNamed:centerOffset:
addAnnotation:withPinColor:
Here is a sample code, which displays 2 annotations:
CLLocationCoordinate2D mapLocation1 = CLLocationCoordinate2DMake(37.787730, -122.403370);
CLLocationCoordinate2D mapLocation2 = CLLocationCoordinate2DMake(37.794873, -122.397892);
//
MKCoordinateSpan coordinateSpan = MKCoordinateSpanMake(0.1, 0.1);
// Other colors include red and green pins
[self.map addAnnotation:mapLocation1 withPinColor: WKInterfaceMapPinColorPurple];
[self.map addAnnotation:mapLocation2 withPinColor: WKInterfaceMapPinColorRed];
[self.map setRegion:(MKCoordinateRegionMake(mapLocation, coordinateSpan))];

Is there a way to change what the disclosure button in Apple Maps does?

I have tried to use MapView, but after finding out that I won't be able to add directions, I am switching to Apple Maps. At first I wanted to add a navigation bar so that I could go back to my app from Apple Maps, but I have been informed that that's not possible. So now, I want to know if I can change the page that opens when I click an annotation view disclosure button in Apple Maps, and possibly lead it back to my app that way by opening one of my local view controllers.
Apple is giving me a hard time with navigating these maps...
If it is possible, please give a code sample or something, or explain what else I can do to lead Apple Maps back to my app.
So far, I use this code to open Apple Maps:
- (IBAction)mapPressed1:(id)sender
{
CLLocationCoordinate2D miamizoo = CLLocationCoordinate2DMake(25.613336,-80.398437);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:miamizoo addressDictionary:nil];
MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
item.name = #"Miami Zoo";
[item openInMapsWithLaunchOptions:nil];
}
Thanks; all help is appreciated.
my initial quess is that it will not be possible because apple maps is an independent app from the one you're writing.
Apple maps is a ready, closed up application without any modification possibilities, so you will not be able to change the behavior of the disclosure button / add a bar into apple maps.
Anyone, please prove me wrong, because I also was puzzled about the missing direction feature in the map API.You will either have to use overlays for directions in map API or you bite the bullet and buy a ready made direction api for maps.
The way I'm currently doing it is similar to yours. I start up apple maps with a direction request and change into it, no overlays.
I hope they will make up for that in ios7.
They do make up for it. Didnt have the chance to put my hands on the ios7 beta, but it will be there.
El

Resources