4

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 !!!

SashaZd
  • 3,315
  • 1
  • 26
  • 48
  • I think you would need to set the location managers distance filter to probably 5 meters... and do this. Yes, it is very memory consuming.... but I am pretty sure it is the only way – MCKapur Oct 29 '12 at 10:00
  • so reload the entire map each time you want to update current location ? That sounds very tedious. Is there no other way ? Google Devs on the forum please answer !! – SashaZd Oct 29 '12 at 14:20
  • I don't think there is another way. – MCKapur Oct 29 '12 at 14:21

2 Answers2

3

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

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
0

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

ArK
  • 20,698
  • 67
  • 109
  • 136