Mapbox online map on iOS - 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.

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.

MapBox loads wrong map

I followed the installation steps from mapbox ios sdk. Then, i run my app in simulator and everything was right with the example map id into RMMapBoxSource.Although when i made a custom map in mapbox online and tried to load it into my app it always loads a map from Washighton DC city and not my custom map. Can anyone tell me whats going wrong with this? Here is the code from the controller that tries to load map:
- (void)viewDidLoad
{
[super viewDidLoad];
RMMapBoxSource *tileSource = [[RMMapBoxSource alloc] initWithMapID:#"hoya21.map-nkbz19y4"];
RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:tileSource];
[self.view addSubview:mapView];
}
Go to mapbox.com, open up your map project, click the gear at the top of the window next to the map name and then check the box next to "Save current map position".

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

How to implement iOS Google Maps SDK

I just have a question and can't seem to find it anywhere.
I"m new to iOS development and trying to use Google Maps inside my application.
I went thru the example they give you here.
#import "DemoViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#implementation DemoViewController {
GMSMapView *mapView_;
}
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
longitude:103.848
zoom:12];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = mapView_;
}
#end
But as you can see the they set self.view = mapView_; and the UIView class doesn't have a view function.
I want the map to be inside a UIView I have that is inside another ViewController
Did I lose you yet? Either ways here is a picture.
So inside of the view (or whitespace) I want the map to load.
Thanks guys for the help.
So you've got a GMSMapView. And you can make one view a subview of another in the interface with addSubview:. I wouldn't do it in loadView if I were you, though. viewDidLoad is the earliest good opportunity.
I think your real problem is that you're way ahead of yourself. You're trying to do this without know how views work, how view controllers work, etc. I recommend you take a deep breath and learn about iOS programming before you jump in with all four feet. Otherwise you don't know what your code (or Google's code) even means.
I found a solution that works for me if anyone needs to do something similar.
I just used a container view and then made separate UIViewController class (that has the google maps sdk code add a map section) and then hooked it up to my main ViewController by using [self.view addSubview:googleMapsView]; googleMapsView being my container view that I connected to the main ViewController.
I did an exact same thing here.
Simply added a View of type GMSMapView via interface builder and then set up the properties in controller.
Please try below code.
#property (strong, nonatomic) IBOutlet GMSMapView *mapView;
-(void)addAllPinsOnMapView
{
arrMapPin=[[NSMutableArray alloc] init];
for(int i = 0; i < arrOfferList.count; i++)
{
GMSCameraPosition *cameraPosition=[GMSCameraPosition cameraWithLatitude:[[[arrOfferList objectAtIndex:i] objectForKey:#"latitude"] floatValue] longitude:[[[arrOfferList objectAtIndex:i] objectForKey:#"longitude"] floatValue] zoom:12];
// mapView = [GMSMapView mapWithFrame:CGRectZero camera:cameraPosition];
_mapView.camera = cameraPosition;
_mapView.myLocationEnabled=YES;
GMSMarker *marker=[[GMSMarker alloc]init];
marker.position=CLLocationCoordinate2DMake([[[arrOfferList objectAtIndex:i] objectForKey:#"latitude"] floatValue], [[[arrOfferList objectAtIndex:i] objectForKey:#"longitude"] floatValue]);
marker.title = [[arrOfferList objectAtIndex:i] objectForKey:#"business"];
marker.map=_mapView;
_mapView.delegate = self;
}
}
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:
(GMSMarker *)marker {
NSPredicate *result;
result=[NSPredicate predicateWithFormat:#"business CONTAINS[c] %#",marker.title];
NSArray * array = [arrOfferList filteredArrayUsingPredicate:result];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
objOfferDetailsViewController.dictOfferDetails=[array objectAtIndex:0];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
- (IBAction)btnLocateMe:(UIButton *)sender
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[[[AppDelegate initAppDelegate].DictLocation objectForKey:#"Latitude"] floatValue] longitude:[[[AppDelegate initAppDelegate].DictLocation objectForKey:#"Longitude"] floatValue] zoom:14];
[_mapView animateToCameraPosition:camera];
}

Resources