Google Maps SDK drop marker - ios

I am using Google Maps SDK in my Iphone app.
Now I want to drop marker when user touch and hold on map more than 2 sec on touched place, but I can't find any solution.
Thank you...

I have found solution.
You should implement GMSMapViewDelegate protocol on the view controller that displays the map and listen to didLongPressAtCoordinate event.
#interface MapViewController : UIViewController<GMSMapViewDelegate>
and
-(void) mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate{
GMSMarker *marker3 = [[GMSMarker alloc] init];
marker3.position = coordinate;
marker3.title = #"170 Asbury Anderson Rd";
marker3.snippet = #"US";
marker3.map = mapView_;
}
Protocol GMS Map View Delegate

Related

Dragging doesn't work in Google Maps iOS app?

I have the following method defined in a view controller class. At the last line of this code I declare the draggable attribute to be set to YES, but surprisingly it doesn't work when in the app.
What may cause this?
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
CLLocationDegrees latitude = -33.861;
CLLocationDegrees longitude = 151.20;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(latitude,longitude);
marker.map = _mapView;
marker.draggable = YES;
}
You need to long push the marker then you can drag it.

How to show marker and info window together in IOS when i tap on map

I am trying to Shown the marker and it's info window together in ios when I tapped on map but didn't work for me here is my sample of code
- (void) mapView: (GMSMapView *) mapView
didTapAtCoordinate: (CLLocationCoordinate2D) coordinate{
CLLocation *destination_lat_long = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
GMSMarker *marker_test = [[GMSMarker alloc] init];
marker_test.position = coordinate;
marker_test.title = #"Location selected";
marker_test.snippet = #"Testing";
marker_test.map = self.MyMapView;
//Show info window on map
[self.MyMapView setSelectedMarker:marker];
}
I don't understand why it's not working?
I want to populate the info window on marker set.
Related to comments:
Sure you can but I think without making custom Markers and InfoWindows it is only possible for one marker:
GMSMarkerOptions *myLocationOptions = [GMSMarkerOptions options];
myLocationOptions.title = #"Your title goes here";
myLocationOptions.snippet = #"Snippet goes here";
self.MapView.selectedMarker = [self.MapView addMarkerWithOptions: locationOptions];
But if you want to show more markers with their infoWindows you'll have to make a custom solution.

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.

How to get Google map in ios 6.0 and above versions

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:

User Location-Mapview

I would like to find out userlocation coordinate while my app is loading. I have implemented following code but it returns 0.000
mapView.showsUserLocation=YES;
CLLocationCoordinate2D annotationCoordinate;
annotationCoordinate.latitude=mapView.userLocation.location.coordinate.latitude;
NSLog(#"%f",annotationCoordinate.latitude);
I could not able to figure out. Any help?
First of all you should take into account that it takes time to retrieve the user location. Moreover the user can disable the location service for your application or even the location service can be unavailable during the connectivity conditions. So you'd better to rethink your application starting procedures.
When you make up you decision take a look at mapView:didUpdateUserLocation: method of MKMapViewDelegate protocol. After this method fires out the location can be available via the userLocation property of the MKMapView.
UPDATE
In case you want to open map view with the user location already checked, you may consider using CLLocationManager and CLLocationManagerDelegate. This way you can check if the location service is available and open map view after the method locationManager:didUpdateToLocation:fromLocation: fires up.
For the complete info take a look at Getting the User’s Location programing guide
You can not get users location coordinate in view did load what you need to do is using the delegate method below.
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(#"coordinates = %f,%f", mapView.userLocation.coordinate.latitude,
mapView.userLocation.coordinate.longitude);
}
Make sure your map object is connected with the delegate
Just tested it should work
1) Add the FrameWork CoreLocation and Mapkit
2) In ViewController.h file
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface MapViewController : UIViewController<MKMapViewDelegate,CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
#property (nonatomic, strong) IBOutlet MKMapView *mapView;
3) In viewController.m file
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
now in didUpdateUserLocation
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
// 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];}
4) Now add Mapview in your UI
NOTE: select MapView and goto Attribute Inspector and CKECK Mark the Shows user location Under BEHAVIOUR
I think you should use this:
#import <CoreLocation/CoreLocation.h>
Then in viewDidLoad method:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
[mapView setRegion:MKCoordinateRegionMake(locationManager.location.coordinate, MKCoordinateSpanMake(0.2, 0.2))];
mapView.showsUserLocation = YES;
NSLog(#"%f",mapView.region.center.latitude);
Okay, so I just managed to fix it myself too. What no one is telling you is that you need to set a key/value pair in the info.plist.
Depending on what method (requestAlwaysAuthorization or requestWhenInUseAuthorization) you need to add a key under the 'Information Property List' dictionary. For the first method use: NSLocationAlwaysUsageDescription and for the second method use: NSLocationWhenInUseUsageDescription .
The value fields of both keys can be set to whatever string you would like to display to the user.
Both keys at the top are what we are looking for.
Now you should see a dialogue that prompts you for confirmation.
PS: No tutorial on the internet listed this step of the process, but when you read the documentation for each of those methods (requestWhenInUse on CLLocationManager) it does mention that nothing gets displayed without those two keys.

Resources