Google Maps iOS SDK didTapInfoWindowOfMarker not working - ios

I have an odd problem where I cannot get this method to do anything! I have added the map view delegate and delcaired the delegate in the top AND header file. I intend to just get a response when the user touches a bubble produced by tapping on a google maps marker
Here is what I have
#import "ViewController.h"
#import "Location.h"
#interface ViewController () <GMSMapViewDelegate>
#property(nonatomic)NSMutableArray* storedLocations;
#property(nonatomic)NSMutableArray* myPlaces;
#end
#implementation ViewController {
GMSMapView *mapView;
}
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker{
UIAlertView* new = [[UIAlertView alloc] initWithTitle:#"Nice!" message:#"Good stuff" delegate:self cancelButtonTitle:#"Well Done!" otherButtonTitles:nil];
[new show];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Create Map View on scene with camera
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0
longitude:0
zoom:0];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;
mapView.delegate = self;
As mentioned at the moment, touching the bubble does nothing

If you want to know if your marker is tapped, you should call the
(BOOL) mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *) marker method
The method you use, it will only been called if the info window of your marker is tapped.

Maybe you have to define a Title,
mapView.title = #"Test title";
then you can tap over the description window.

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.

google map marker hide inside the uisearchbar and not display in center of the map

i am using google map api for display the location and search bar for search the location but when the GSMMarker display it snippet window hide inside the uisearchbar so any own please help me.
-(void) setupMarkerOnMap:(CLLocation *)loc PlaceName:(NSString *) strCityName
{
[[self getGoogleMap] clear];
[self getNextButton].enabled = YES;
placeMarker = [GMSMarker markerWithPosition:loc.coordinate];
placeMarker.map = [self getGoogleMap];
[placeMarker setTappable:NO];
placeMarker.snippet = strCityName;
placeMarker.icon = [UIImage imageNamed:#"LocationMarker.png"];
GMSCameraUpdate *updateCamera = [GMSCameraUpdate setTarget:placeMarker.position zoom:10.0];
[[self getGoogleMap] animateWithCameraUpdate:updateCamera];
[[self getGoogleMap] setSelectedMarker:placeMarker];
}
these my code snippet for marker add in google map and i attached image which can help you.
anyone can help me.
Thanks
First of all, Make sure that your Google map does not stack together with the search bar. Then you can use delegate to help you move the animate the marker's position inside the Google Map when you tap on any of the marker. Example code:-
Implement the Google Map Delegate
#interface YourViewController ()<GMSMapViewDelegate>
#property (weak, nonatomic) IBOutlet GMSMapView *mapView;
#end
Set the mapView Delegate to the current view controller
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
}
Whenever a marker is tapped, the
-(BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker{
[mapView animateToLocation:marker.position];
return YES;
}
If you have everything setup correctly and the map is big enough, info window should be displayed nicely inside the map.

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

iOS Mapping Application New View from Annotation

I am totally new to iOS development, and am creating a mapping application for a local river. The point of the application is to allow users to map out a route on the river by selecting different points. I am using MapKit to work on this, but have run into some issues. My main issue is how to add a button to an annotation so that once clicked, a detail window will open and the user can learn more about the point as well as add it to the trip. Here's my code, any thoughts will help!
#import "ViewController.h"
#import "CoreLocation/CLLocation.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
// Add an annotation
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
point.title = #"Where am I?";
point.subtitle = #"I'm here!!!";
[self.mapView addAnnotation:point];
point.coordinate = CLLocationCoordinate2DMake(33.62258872997,-86.599988937378);
point.title = #"Civitan Park";
point.subtitle = #"Trussville, AL";
[self.mapView addAnnotation:point];
}
#end
Your map view delegate should implement –mapView:viewForAnnotation: and return an annotation view that has one of its accessory view properties set. The normal thing is to set the rightCalloutAccessoryView property to a UIButton whose type is UIButtonTypeDetailDisclosure. You map delegate should also implement -mapView:annotationView:calloutAccessoryControlTapped:, which will be called when the user taps the button in the accessory view. You can then push a detail view controller onto the navigation stack, or whatever else you like.

Resources