How to show india map on google maps in objective c - ios

I am new in iOS and I am facing problem regarding to show India maps on Google Maps
My code is like this first
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726
longitude:73.856255
zoom:3];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//Scrollview
mapView = [GMSMapView mapWithFrame:CGRectMake(10, 140, 750, 350) camera:camera];
}
else
{
//Scrollview
mapView = [GMSMapView mapWithFrame:CGRectMake(10, 140, 550, 350) camera:camera];
}
But When I used UIView and create it using IBOutlet like this
IBOutlet GMSMapView *mapView;
Than the above code not work.How can I show the India map first by using above coordinate.Thanks in Advance!

Get current Location coordinate and Pass on these camera position
CLLocationCoordinate2D coordinate;
float latitude;
float longitude;
coordinate = [self getLocation];
latitude = coordinate.latitude;
longitude = coordinate.longitude;
//pragma mark ----: GET Coordinate2D :----
-(CLLocationCoordinate2D) getLocation
{
CLLocation *location = [_locationManager location];
coordinate = [location coordinate];
return coordinate;
}
CGRect frame = CGRectMake(0, 0, kSCREEN_WIDTH,kSCREEN_HEIGHT);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude longitude:longitude zoom:12];
mapView_ = [GMSMapView mapWithFrame:frame camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.delegate = self;
[mapView_ setCamera:camera];

Below is a Sample Code:
#import <GoogleMaps/GoogleMaps.h>
#interface ViewController ()<GMSMapViewDelegate>
{
GMSMapView *mapView;
GMSMarker *marker;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self showMarker];
}
- (void)showMarker
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726 longitude:73.856255 zoom:3];
mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view addSubview:mapView];
}
#end

Try This code:
#interface ViewController ()<GMSMapViewDelegate>
{
GMSMapView *mapView_;
}
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:18.516726
longitude:73.856255
zoom:3];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//Scrollview
mapView_ = [GMSMapView mapWithFrame:CGRectMake(10, 140, 750, 350) camera:camera];
}
else
{
//Scrollview
mapView_ = [GMSMapView mapWithFrame:CGRectMake(10, 140, 550, 350) camera:camera];
}
NSError *error;
// Set the map style by passing a valid JSON string.
GMSMapStyle *style = [GMSMapStyle styleWithJSONString:kMapStyle error:&error];
if (!style) {
NSLog(#"The style definition could not be loaded: %#", error);
}
mapView_.mapStyle = style;
mapView_.mapType = kGMSTypeNormal;
[self.scrllView addSubview:mapView_];
[_btnMap setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
mapView_.delegate = self;
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
18.516726,
73.856255);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.map = mapView_;
marker.icon=[UIImage imageNamed:#"locationBlue"];
marker.title = #"From";

Related

Custom infobox when tap event

I'm trying to have an info box, same one as the standard for markers, to appear when a my polyline is tapped. I've gotten a NSLog to output when the line is tapped, but now I need to have the infobox appear instead of the NSLog. I've seen some Javascript examples but no objective c ones.
- (void)loadView {
// Create a GMSCameraPosition
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:37.551927
longitude:-77.456292
zoom:18];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(37.551709, -77.456510);
mapView.settings.myLocationButton = YES;
mapView.myLocationEnabled = YES;
self.view = mapView;
mapView.delegate = self;
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.552243, -77.457415)];
[path addCoordinate:CLLocationCoordinate2DMake(37.551054, -77.455443)];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
UILabel *myLabel = [[UILabel alloc] init];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(labelTapped)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[myLabel addGestureRecognizer:tapGestureRecognizer];
myLabel.userInteractionEnabled = YES;
polyline.spans = #[[GMSStyleSpan spanWithColor:[UIColor greenColor]]];
polyline.strokeWidth = 5.f;
polyline.tappable = true;
polyline.map = mapView;
}
- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay
{
NSLog(#"in didTapOverlay");
}
#end
Check the Events guide from the iOS Maps tutorial.
Here's a snippet in Objective-C:
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
longitude:103.848
zoom:12];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.delegate = self;
self.view = mapView;
}
#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView
didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
NSLog(#"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
}
Here's an SO thread demonstrating the use of GMSMapViewDelegate:
1.conform to the GMSMapViewDelegate protocol.
#interface YourViewController () <GMSMapViewDelegate>
// your properties
#end
2.set your mapView_ delegate.
mapView_.delegate = self;
3.implement the GMSMapViewDelegate method
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
// your code
}
Addition: marker.userData is useful. you can set your needed data into it and use it in - mapView:didTapInfoWindowOfMarker:

add google maps in uimaps

I created a viewcontroller with Google maps , but I have no need to insert the card in full size viewcontroller, and I got it ( the new view I added a class GMSMapView) but I need to put this map markers . Example of my marker
CLLocationCoordinate2D position2 = CLLocationCoordinate2DMake(59.957069, 30.323013);
GMSMarker *london2 = [GMSMarker markerWithPosition:position2];
london2.title = #"my office";
london2.snippet = #"description";
london2.map = mapView_;
This is my code
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView_.mapType = kGMSTypeNormal;
self.mapView_.settings.compassButton = YES;
self.mapView_.settings.myLocationButton = YES;
self.mapView_.delegate = self;
[GMSServices provideAPIKey:#"###"];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:1];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
//self.view = mapView_;
GMSMarker *london2 = [GMSMarker markerWithPosition:position2];
london2.title = #"my office";
london2.snippet = #"description";
london2.map = mapView_;
Question - if I add a line self.view = mapView_; the card is reflected on the whole screen with the right markers to me , if I remove , it is reflected without markers , but my desired size - how to fix it ( make a map of the desired size and markers )
You can change your self.view = mapView_;
to the following code:
mapView.frame = CGRectMake(YOUR_MAP_X, YOUR_MAP_Y, YOUR_MAP_WIDTH, YOUR_MAP_HEIGHT);
[self.view addSubview:mapView_];
Your mapView_ will be a subview of your main UIView, instead of occupying the entire screen.

How to reduce the screen size of google map in ios application

In my application I have included google maps API but the problem is, it is occupying the entire screen but I dont want it occupy entire screen as I have other UI controls on the same screen. I have my code pasted below.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:12.9699 longitude:77.6499 zoom:6];
mapView_ = [GMSMapView mapWithFrame: CGRectMake(0,0, 10, 25) camera: camera];
mapView_.myLocationEnabled = YES;
NSLog(#"User's location: %#", mapView_.myLocation);
UIEdgeInsets mapInsets = UIEdgeInsetsMake(100.0,10.0, 10.0, 300.0);
mapView_.padding = mapInsets;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(12.9699,77.6499);
marker.title = #"BANGALORE";
marker.snippet = #"IndraNagar";
marker.map = mapView_;
self.view = mapView_; instead of this add below code
UIView * MApBaseView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];// add your frame size here
[self.view addSubview:MApBaseView];
[MApBaseView addSubview: mapView_];
Try with this code, it work for me:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:14];
mapView = [GMSMapView mapWithFrame:mapViewContent.frame camera:camera];
mapView.myLocationEnabled = YES;
mapView.delegate = self;
[mapViewContent addSubview:mapView];
mapViewContent is your view custom.
You should replace marker.map = mapView_; as [self.view addSubview:mapView_];
See the below code
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
longitude:locationManager.location.coordinate.longitude
zoom:16];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 44, self.view.bounds.size.width, self.view.bounds.size.height-44) camera:camera];
mapView_.myLocationEnabled = YES;
[self.view addSubview:mapView_];

I can't see map after adding google map sdk for ios

I want to add a google map above a UIViewController. But I can't see anything except some markers I defined. The problem looks like this:
And here is the related code:
- (void)viewDidLoad {
previousContext = [EAGLContext currentContext];
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:10];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 1136, 640) camera:camera];
//mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
mapView_.delegate = self;
// Listen to the myLocation property of GMSMapView.
[mapView_ addObserver:self
forKeyPath:#"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];
[EAGLContext setCurrentContext: previousContext];
//add makers
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(39.900285, 116.274020);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = #"aaa";
marker.snippet = #"population : 5";
marker.infoWindowAnchor = CGPointMake(0.5, 0.5);
marker.map = mapView_;
marker.icon = [UIImage imageNamed:#"tempmarker.png"];
CLLocationCoordinate2D position2 = CLLocationCoordinate2DMake(39.860285, 116.274020);
GMSMarker *marker2 = [GMSMarker markerWithPosition:position2];
marker2.title = #"bbb";
marker2.snippet = #"population : 5";
marker2.infoWindowAnchor = CGPointMake(0.5, 0.5);
marker2.map = mapView_;
marker2.icon = [UIImage imageNamed:#"tempmarker2.png"];
//add buttons:directRoom, rank, achievement, mission, home
....
[self.view insertSubview: mapView_ atIndex: 0];
[EAGLContext setCurrentContext:nil];
// Ask for My Location data after the map has already been added to the UI.
dispatch_async(dispatch_get_main_queue(), ^{
mapView_.myLocationEnabled = YES;
});
}
So, how to deal with this problem, thanks a lot!
For reference, see the demo from Google (copied below). It's similar to what you posted, but you can try a couple of things:
make sure your API key is valid and the API can fetch tiles
check the z-index ordering of the map view you're inserting: [self.view insertSubview: mapView_ atIndex: 0]; inserts behind everything else. Try [self.view addSubview:mapView_]
Demo code, from Google (https://developers.google.com/maps/documentation/ios/):
#import <GoogleMaps/GoogleMaps.h>
#import "DemoViewController.h"
#implementation DemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:6];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = #"Hello World";
marker.animated = YES;
self.view = mapView;
}
#end
Check whether you have entered the google API key correctly in the didFinishLaunchingWithOption in your app delegate
[GMSServices provideAPIKey:#"yourGoogleAssignedSDKKeyGoesHere"];
And your xcode should be 4.5 or later

Cannot move a camera on GMSMapView of Google Maps for iOS

I have created a GMSMapVIew objects as shown in code. Unfortunately, camera is not set on the right coordinates:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
mapView_ = [[GMSMapView alloc] initWithFrame:CGRectMake(505, 280, 427, 200)];
mapView_.camera = camera;
mapView_.myLocationEnabled = YES;
UIViewController *mapController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
mapController.view = mapView_;
[self addChildViewController:mapController];
[self.view addSubview:mapView_];
I have tried additionally to relocate camera with following code, but with no success either:
CLLocationCoordinate2D current = CLLocationCoordinate2DMake(latitude,longitude);
GMSCameraUpdate *currentCam = [GMSCameraUpdate setTarget:current];
[mapView_ animateWithCameraUpdate:currentCam];
Does anybody have an idea, what am I doing wrong, or is this simple a bug in Google Maps for iOS?
Are you using the same
CLLocationCoordinate2D current = CLLocationCoordinate2DMake(latitude,longitude);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
latitude and longitude? The obviously it wont work as nothing changes ...

Resources