Dragging doesn't work in Google Maps iOS app? - ios

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.

Related

google autocomplete in objective c

I want to use google autocomplete.
I have already implemented UISearchBar and google map
This is my google map code on viewDidLoad
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:CLLocationCoordinate2DMake(22.9937266, 72.4987654) zoom:15.0f];
_googleMapView = [GMSMapView mapWithFrame:self.mapView.bounds camera:camera];
_googleMapView.myLocationEnabled = YES;
_googleMapView=_mapView;
_googleMapView.settings.allowScrollGesturesDuringRotateOrZoom = YES;
marker = [[GMSMarker alloc] init];
// marker.position = CLLocationCoordinate2DMake(_locationManager.location.coordinate.latitude, _locationManager.location.coordinate.longitude);
marker.position = CLLocationCoordinate2DMake(22.9937266, 72.4987654);
marker.title = #"Ahmedabad";
marker.icon=[UIImage imageNamed:#"ic_map_car.png"];
marker.snippet = #"India";
marker.map = self.googleMapView;
I want "when I type any location in the search bar it will display on UITableView and when I select that location a pin is set to that location."
I already try https://developers.google.com/places/ios-api/autocomplete but it's not useful.
give me some sample demo.
thanks in advance.
Following is a really good and easy to use the library for implementing google search with autocomplete text field.
https://github.com/TheMrugraj/MVAutocompletePlaceSearchTextField
How to USE : ()
Bind 'MVPlaceSearchTextField' as Class for 'UITextField' in the
Storyboard.
Set its delegate named 'placeSearchDelegate'.
Set your API Key as value of Property "strApiKey" Create iOS Key to
use it here from Google Console, for more info
Add following in didFinishLaunchingWithOptions of AppDelegate.
[GMSServicesprovideAPIKey:#"YOUR API KEY"];
Try following to add a pin for user selected place ,You can add GSMarker with coordinates:
-(void)placeSearch:(MVPlaceSearchTextField*)textField ResponseForSelectedPlace:(GMSPlace*)responseDict . {
CLLocation *userSelectedLocation = [[CLLocation alloc] initWithLatitude:responseDict.coordinate.latitude longitude:responseDict.coordinate.longitude];
marker.position = CLLocationCoordinate2DMake(userSelectedLocation.coordin‌ate.latitude, userSelectedLocation.coordinate.longitude);
marker.map = self.googleMapView; [_googleMapView animateToLocation:userSelectedLocation.coordinate];
[self.googleMapView animateToCameraPosition:[GMSCameraPosition cameraWithTarget:self.googleMapView.camera.target zoom:15.0f]];
}

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 Maps SDK drop marker

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

Reload annotations in a map view

I am adding annotations as hardcoded values into the method
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
CLLocationCoordinate2D coords1;
coords1.latitude = 40.579754;
coords1.longitude = -120.1303229;
MKPointAnnotation *annotationPoint1 = [[MKPointAnnotation alloc] init];
annotationPoint1.coordinate = coords1;
annotationPoint1.title = #"TJ11234";
annotationPoint1.subtitle = #"Power Failure \n Start Time:12hrs 30min \n End Time:14hrs ";
[self.mapView addAnnotation:annotationPoint1];
with values of lats and longitude hardcode intially its loading fine, but when I go to another page and come back to the page the annotations are not loading. What should I do to correct it?
mapView:didUpdateUserLocation: is called whenever a new location update is received by the map view. Check the documentation.
If you want to set annotation when your map is shown, you can place your code in viewDidAppear or similar.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]
CLLocationCoordinate2D coords1;
coords1.latitude = 40.579754;
coords1.longitude = -120.1303229;
MKPointAnnotation *annotationPoint1 = [[MKPointAnnotation alloc] init];
annotationPoint1.coordinate = coords1;
annotationPoint1.title = #"TJ11234";
annotationPoint1.subtitle = #"Power Failure \n Start Time:12hrs 30min \n End Time:14hrs ";
[self.mapView addAnnotation:annotationPoint1];
}
Hope this helps.

Adding MultiplePointAnnotation In MapView ios

Im trying to load annotation point into mapview in which i have the seperate array for latitude and a seperate array for longitude here is my code
- (void)viewDidLoad
{
[super viewDidLoad];
delegate=[[UIApplication sharedApplication]delegate];
delegate.arrForLat=[[NSMutablearray alloc]initwithobjects:#"33.930216",#"33.939788",#"33.9272",#"33.902237"];
delegate.arrForLon=[[NSMutablearray alloc]initwithobjects:#"-118.050392",#"-118.076549",#"-118.065817",#"-118.081733‌​"];
for (int i=0 ; i< delegate.arrForLat.count;i++)
{
annotationCoord.latitude = [[delegate.arrForLat objectAtIndex:i] doubleValue];
annotationCoord.longitude = [[delegate.arrForLng objectAtIndex:i] doubleValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
[MapView addAnnotation:annotationPoint];
}
}
Now i get only 1 annotation point in mapview but i have 4 coordinates.I don't know what mistake i have done.
Ah, I think I see it. You only have one annotationCoord. On the first trip through the loop you set its lat and long to (33.930216,-118.050392) and create a new object called annotationPoint point its coordinate attribute to your annotationCoord. Then on the next time through the loop you edit annotationCoord by giving it new coordinates. But it's still the same annotationCoord and the annotation you added to the map is still using it, now with the new coordinates.
So the solution is to make a new CLLocationCoordinate2D each time through the loop.

Resources