google autocomplete in objective c - ios

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]];
}

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.

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.

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.

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:

Mapbox online map on iOS

I'm totally new to mapbox API on iOS , i follow the instruction on there site and make a custom map with marker -
My Map Online Link
- and i add the binary framework and it load with the map without any marker
#import <MapBox/MapBox.h>
-(void)viewWillAppear:(BOOL)animated{
RMMapView *map =[[RMMapBoxSource alloc]initWithMapID:#"scorpioo.map-a6l64b06"];
RMMapView *mapV = [[RMMapView alloc] initWithFrame:view.bounds andTilesource:map];
}
so anyone can tell me why it not shown ? or know how can i show the marker that i put on the online map on my ios ?
This is possible using this method of RMMapBoxSource:
http://www.mapbox.com/mapbox-ios-sdk/api/#//api/name/initWithMapID:enablingDataOnMapView:
Create your RMMapView first, then create your RMMapBoxSource, pass the map view as the second argument. This will pull down server-side markers and automatically display them.
Here is an example project which shows this:
https://github.com/mapbox/weekend-picks-template-ios
The technology here is called simplestyle.
You need to add the following lines in the above code. So that you can get the desired marker :
RMPointAnnotation *annotation = [[RMPointAnnotation alloc] initWithMapView:map coordinate:MENTION_COORDINATES_HERE andTitle:#"Hello, world!"];
[mapView addAnnotation:annotation];
Complete Example :
RMMapBoxSource *tileSource = [[RMMapBoxSource alloc] initWithMapID:#"examples.map-z2effxa8"];
RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:tileSource];
[self.view addSubview:mapView];
RMPointAnnotation *annotation = [[RMPointAnnotation alloc] initWithMapView:mapView
coordinate:mapView.centerCoordinate
andTitle:#"Hello, world!"];
[mapView addAnnotation:annotation];
Hope that helps.

Resources