How to get Google map in ios 6.0 and above versions - ios

Apple has taken out google map from ios 6.0 version onwards.Apple Using MkMapView that was not that much clear like google map..I used GoogleMapOverlay it displayed the Google map inside the MkMapView..GoogleMapOverlay displays the worldMap i want to move to specific loaction using latitude and longitude...If i specify the latitude and longitude position in GoogleMapOverlay example am getting that particular position alone in rectangle shape overlay at the back i can see my mkmapview...can any one please guide me to resolve this..Thank you

You can use Google Maps on iOS 6 by adding a UIWebView and adding Map on it.

You can use the google map sdk for >= ios6
https://developers.google.com/maps/documentation/ios/
here is sample code from google sdk ios
#import "YourViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#implementation YourViewController {
GMSMapView *mapView_;
}
// You don't need to modify the default initWithNibName:bundle: method.
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:24.451794 longitude:54.391412 zoom:12];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position=CLLocationCoordinate2DMake(24.451794,54.391412);
marker.snippet = #"Abu Dhabi";
marker.title = #"Al Jazira Sports and Cultural Club";
marker.map = mapView_;
}
#end
output:

Related

Why google map doesn't load in iOS using the Google Maps API?

I am trying to integrate a Google map in my iOS application using the Google map API. However, the map doesn't want to load. I am pretty sure that I integrated the right API key, and the appropriate framework. What is wired is that I don't have the map loaded, but have the Google Logo at the bottom of the page. Here is the code of the viewController Page, and a snapshot of the execution:
#import "ViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#implementation ViewController{
GMSMapView *mapView_;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.53805 longitude:-5.0766 zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc]init];
marker.title = #"Lab 7";
marker.snippet = #"Al Akhawayn University in Ifrane";
marker.map = mapView_;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
The first thing I'm seeing wrong here is the way you've created your marker. You need to inform the coordinates of it, something like this:
CLLocationCoordinate2D addressLocation = CLLocationCoordinate2DMake(self.initialLat, self.initialLong);
GMSMarker *marker = [GMSMarker markerWithPosition: addressLocation];
marker.title = #"Lab 7";
marker.snippet = #"Al Akhawayn University in Ifrane";
marker.map = mapView_;
Second thing, when you write:
mapView_.myLocationEnabled = YES;
You're telling the mapView to focus in your location, ignoring your camera coordinates you set earlier.
What might be causing your beige screen with Google's logo is that the Simulator doesn't have a built-in GPS, so your localization won't show on the simulator. Try commenting that line...
That was all I could think of with this code you've posted.

Issue Implementing the Google Maps API Into iOS Application Project

I may be missing something, but I followed the steps indicated at the Google Maps SDK for iOS Site, but so far I have had no success. I tried running the sample code they have at the bottom of the page, and my compiler keeps bugging me with an uncaught exception.
Here is my implementation:
#implementation ViewController {
GMSMapView *mapView_;
}
Followed by this in the viewDidLoad:
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
I did include line:
[GMSServices provideAPIKey:#"API Key"];
and replaced the API Key string with my actual API Key. Yet I get this at compile time.
I used a breakpoint, and the exception seems to originate when executing this line:
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
Any of your help would very much be appreciated.
I would guess it wants a minimum frame size. I didn't see anything in the docs, but I would try this...
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0,0, 200, 200) camera:camera];
Or whatever frame size you want with an actual width and hight.
Edit
After further review of your code I see
self.view = mapView_;
It is possible that mapView_ isn't actually a GMSMapView.
Edit Edit
After getting the full error log it sounds like it is an import or setup issue.
I would verify that none of the require imports got missed and that the required linker flag -ObjC was added correctly.
Hopefully that helps =)

IOS Google Map SDK - Google Map not updating to current location

I am trying to implement my current location within a sub view using Google Map SDK for IOS. I am trying to implement the GMSMapView as an IBOutlet.
My header file has the code
#import <UIKit/UIKit.h>
#import <Google-Maps-iOS-SDK/GoogleMaps/GoogleMaps.h>
#interface TripLandingViewController : UIViewController
#property IBOutlet GMSMapView *mapView;
#end
My .m file has the code
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"Tile.png"]];
self.mapView.myLocationEnabled = TRUE;
NSLog(#"\n\n\n My Location is %f,%f \n\n\n",self.mapView.myLocation.coordinate.latitude,self.mapView.myLocation.coordinate.longitude);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.mapView.myLocation.coordinate.latitude
longitude:self.mapView.myLocation.coordinate.longitude
zoom:10];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
No matter, what hardcoded value i provide as parameters for coordinates in camera. I am getting the wrong location (here UK) which is not at all updating.
But Instead when i tried
self.View = [GMSMapView mapWithFrame:CGRectZero camera:camera];
I was able to load correct map View in the Main View with correct location coordinates.
I tried all the answers on adding Google Map to SubViews through stackoverflow.
Cannot put a google maps GMSMapView in a subview of main main view?
How to set the frame for mapview - in google GMSMap for iOS6
How put Google MapView in UIView?
Google Maps iOS SDK, Getting Current Location of user
But nothing seems to work. Please Help since I am new to IOS Programming.
Use:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0 longitude:0 zoom:15];
self.mapView.camera = camera;
instead of using:
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
I'm not totally sure why, but this method works when your GMSMapView is a subview of your UIViewController.

Google Maps iOS SDK crash

I use google maps iOS SDK with storyboard. Application starting with Navigation View Controller that has a Root View Controller with map.
#implementation MyViewController
#synthesize btnMyLock;
#synthesize btnNearby;
GMSMapView *mapView_;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:20
longitude:20
zoom:0];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
[marker setIcon:[UIImage imageNamed:#"pin"]];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
mapView_.settings.compassButton = YES;
[mapView_ addSubview:btnMyLock];
[mapView_ addSubview:btnNearby];
}
Button btnMyLock push the Table View Controller. In iOS 7 it's ok. But iOS 6 my app crashes. Sometimes crash with EXC_BAD_ACCESS (code=1) or code=2
Problem that I used Autolayout view.
you forgot step 4: "Drag the GoogleMaps.bundle" from the Resources folder to your project.
I suggest putting it in the Frameworks group. When prompted, ensure "Copy items into destination group’s folder" is not selected. i encountered the same problem, and this fixed it.
I don't know if it's causing the problem, but I wouldn't do:
self.view = mapView_;
Just add the mapView_ as a subview, like:
[self.view addSubview:mapView_];
In general EXC_BAD_ACCESS crashes are caused when you are mismanaging memory (e.g. an object is being deallocated prematurely). Try to find out what object the crash is happening on.
Create your buttons in code, not from the xib as IBOutlets. Otherwise they are not loaded since you are not using the xib.
Use this code when you use Google map and then check its not crash when you navigate to another screen.
- (void)dealloc {
[super dealloc];
[mapView_ removeObserver:self
forKeyPath:#"myLocation"
context:NULL];
}

GMSMapView always display the same location iOS

as the title says no matter what coordinates I give I see the same location.
Here is my code:
I am using storyboard and I have a subview inside my view. The subview is of type GMSMapView, and correctly linked.
.h
#property (strong, nonatomic) IBOutlet GMSMapView *mymap;
.m
#implementation DealViewController
{
GMSMapView *mapView_;
}
#synthesize mymap=_mymap;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view layoutIfNeeded];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 300, 300) camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.mapType = kGMSTypeSatellite;
mapView_.delegate = self;
self.mymap=mapView_;
}
I also tried this, but I get the same:
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
What is wrong with the above?
After hours of cruel research of the same problem I've found that viewDidLoad method should looks like this:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:obj.latitude
longitude:obj.longitude
zoom:12];
self.mapView.camera = camera;
}
In other words in this case you should NOT assign any value (like '[GMSMapView mapWithFrame:CGRectMake(0, 0, 300, 300) camera:camera];') to self.mapView, just set it's property 'camera' value.
This works for me. I hope this will save time for someone else too.
If you are using storyboards make sure you have set the type of the view to be a GMSMapView in the storyboard UI.
Then all you should need to do is:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view layoutIfNeeded];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
self.mymap.camera = camera;
self.mymap.myLocationEnabled = YES;
self.mymap.mapType = kGMSTypeSatellite;
self.mymap.delegate = self;
}
There is a storyboard example that is available on the Google Maps github page.
I think this is your problem:
#property (strong, nonatomic) IBOutlet GMSMapView *mymap;
#implementation DealViewController
{
GMSMapView *mapView_;
}
#synthesize mymap=_mymap;
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 300, 300) camera:camera];
Your map is coming in from your storyboard, called mymap. You create an instance variable called mapView_ but you synthesize mymap to _mymap...which is different.
Rather than using an instance variable, just access the property directly. Replace all the mapView_ instances with self.mymap.
For example:
self.mymap = [GMSMapView mapWithFrame:CGRectMake(0, 0, 300, 300) camera:camera];
As to why it doesn't move to the user's location - here's what the Google Maps iOS SDK documentation has to say about the myLocationEnabled property:
myLocationEnabled - Controls whether the My Location dot and accuracy circle is enabled.
...what it doesn't do is move the map to the current user's location. It only shows the user's location dot and circle on the map.
Your map is always displaying the same location because you never change it. You create a camera set to (-33.8683, 151.2086), ask the map to show the user's location indicator, but don't ask the map to change its location to that of the user.
To do this you can use the map's myLocation property to obtain the current location of the user, and then the animateToLocation method to move the map accordingly.
GMSMapView seems to struggle fitting to GMSCoordinateBounds in these situations:
1) You init the GMSMapView with a .zero frame
2) The GMSMapView is not yet visible on the screen
3) The GMSMapView is a subview of any given UIViewController
In any of these three cases you have to set the camera explicitly:
let camera = GMSCameraPosition.camera(withTarget: B.center, zoom: 19)
self.map.camera = camera

Resources