Updating Current Location in Google Maps using UIWebview in iOS - ios

I have a WebView I created in app which calls Google Maps Directions to plot out the route between the Current Location and a POI.
The entire google map with directions is loaded as soon as the webView loads. Now I need to update the map with my current location. As in, I want the flag/icon representing my current location to move along with the user while he is travelling. But the only way I seem to be able to do this so far, is reloading the entire map by calling the new location.
This is very expensive in both time/data usage. Is there a better way that I'm missing ?
Here's my code :
CLLocationCoordinate2D destination = { 37.773768,-122.408638 };
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&output=embed",
myLocation.coordinate.latitude, myLocation.coordinate.longitude, destination.latitude, destination.longitude];
NSURL *url=[NSURL URLWithString:googleMapsURLString];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Someone please help !!!

Use the GeolocationMarker from the Google Maps API 3 Utility Library. It was created for this purpose.

u can use..
CLLocationManager for getting user's location
UIWebview is not use for location fetching..

Related

Add transport type when showing Directions on map

How can I add transport type when showing Directions on map
I have used this code so far, but it is showing Walking distance on map
NSURL *URL = [NSURL URLWithString:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"];
[[UIApplication sharedApplication] openURL:URL];
You can add one extra param directionsmode for different direction mode like below :
NSURL *URL = [NSURL URLWithString:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&directionsmode=transit"];
There are many types of direction mode :
driving
transit
bicycling
walking
Also you can use URLSchema for open app with schema like below Google Map Guide
Google Map URLSchema Guide : https://developers.google.com/maps/documentation/ios-sdk/urlscheme

How to show and search in google autocomplete just place my current city(area)?

There are problems with auto complete, to me google autocomplete search bar is filling writes all cities in the world but I need only the address of my city.
You can use the GMSCoordinateBounds, which is
A object which restrict the results to a specific area specified by latitude and longitude bounds.
In additional, There are some Location Biasing options for the JS API, but no sure if iOS API has them too.
I found information, we cant search just in city.We can minimum set search in Country. Google say - they will fix it in next version.
NSMutableString *url = [NSMutableString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%#&sensor=%#&components=country:%#""&key=%#",
[input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
SPBooleanStringForBool(sensor), countryCode,key];
This worked for me:
GMSVisibleRegion visibleRegion = self.mapView.projection.visibleRegion;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:visibleRegion.farLeft coordinate:visibleRegion.nearRight];

How can we open the Maps app for ios 6 within the app interface

I am using the following code for Map turn by turn navigation for iOS 6,
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)])
{
// Create an MKMapItem to pass to the Maps app
CLLocationCoordinate2D coordinate =
CLLocationCoordinate2DMake(16.775, -3.009);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate
addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:#"My Place"];
// Pass the map item to the Maps app
[mapItem openInMapsWithLaunchOptions:nil];
}
It's redirecting me onto the Maps app so ,What i need,i need to open up this within my app interface so as user can remain in the app and not quit the app interface.
Please suggest some ideas to control this.
MKMapKit does not support navigation in MKMapView, you will need to send the user to map.app.
Your only option is to build the navigation your self if you really want to turn by turn navigation with in your app.
As rckoenes said, you have to implement this yourself if you don't want to launch an external app.
If you plan to do a simple version of turn-by-turn navigation, you can get the relevant data via the Google Maps Directions API:
https://developers.google.com/maps/documentation/directions/
From the JSON (or xml) response you get the driving instructions and location data for every step and waypoint. Also a string under the tag "overview_polyline" is provided here. You can draw the route directly on the map by using this string as GMSPath if your're working with the Google Maps IOS SDK.
The main challenge of a self-written navigation app is constructing a robust logic for tracking the user and providing turn-by-turn instructions accurately, as well as exception handling (e.g. losing signal in tunnels...). But just showing the route and the instructions visually should be relatively easy.

iOS Apple Map native links - URL Scheme examples

In one of my projects I'm capturing the Lat/Long coords in a core data store, and later on providing this information in an email with Attached PDF.. On the receiving end, I'd like the convenience of another iPhone user to be able to click on the link, and go to that location in Apple Maps
I find the native apple map comes up, but it's simply an open map view w/no pin:
NSString *appleLink2 = [NSString stringWithFormat:#"http://maps.apple.com/maps
ll=%#,%#",self.lat,self.lon];
I'm creating the clickable in a common fashion with a CGRect, and NSURL
It appears on the surface that I should probably get the street address instead of the Lat/Long coords also, and use the address for better map resolution... Thoughts?
Also, I'm looking for examples of Apples URL Schemes to query strings mentioned in the Docs, but can't find any real examples... ll = , son =, t = , z =. I understand saddr and daddr, and am surprised that I can't find any reference or real examples anywhere.
If you want the pin to be placed on the map in Apple's Maps app, use a 'q' instead of 'll' in the URL:
NSString *appleLink2 = [NSString stringWithFormat: #"http://maps.apple.com/maps?q=%#,%#", self.lat, self.lon];
The following apple link has all details for the questions
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html
USE NSString for URL
NSString *appleLink2 = [NSString stringWithFormat:#"http://maps.apple.com/maps
ll=%#,%#",self.lat,self.lon];
NSURL *myUrl = [NSURL URLWithString:[appleLink2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Then use myUrl is as URL.

Add address annotation when finding route via google maps api

I'm using google maps to get directions from one place to another. Here is the code
NSString *mapAPIString = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
sourceAddress.coordiate.latitude,
sourceAddress.coordiate.longitude,
destAddress.coordiate.latitude,
destAddress.coordiate.longitude,
];
NSURL *url = [[NSURL alloc] initWithString:mapAPIString];
[[UIApplication sharedApplication] openURL:url];
The code works perfect. But both addresses are marked as 'Unknown address' in iOS Map App. Is it possible to add custom title for each address ?
iOS 6 is still under NDA, but if you have access to the docs have a look at them and you will probably find useful information for this problem.

Resources