I'am trying to add a view to google map which both have been created using the storyboard. In order to do this, I've changed this part of the code:
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
to this:
mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
self.mapView.myLocationEnabled = YES;
[self.view insertSubview:mapView atIndex:0];
it works, but the default "My location button" disappeared after this. Is there a way to get back the default button? I would greatly appreciate any help.
I tried this solution My location button not appearing in view (Google maps SDK, ios)
but it didn't work or maybe I didn't get it correctly, if this is the only solution could you please explain it in details?
I got around this problem by creating a button from the storyboard and connect it to this action.
- (IBAction)MyLocation:(id)sender {
CLLocation *location = mapView.myLocation;
if (location) {
[mapView animateToLocation:location.coordinate];
} }
In my case, if I place the created button on the lower right/left corner still can't get it but everywhere else is just fine. (I don't know why I think because of inserting the map at index 0 or something like that).
Are you requesting access to location services correctly? It's done a bit different in iOS 8. Try adding the following to you Info.plist file and let me know if it works:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message to request location usage permission goes here</string>
Related
Hey I'm a beginner and learning Ios App development and i want to know that how to set the the user location programmatically like we did here using IDE (Custom Location) :-
I setup everything and location system is working fine in my simulator (fake location) what i have to do if i want to do the same thing programmatically i worked myself and found a little solution but its not helping me out like something is missing here's my code :-
- (IBAction)showMyLocation:(id)sender {
CLLocation *currentLocation=[[CLLocation alloc]initWithLatitude:75.14254 longitude:75.14254];
_map.userLocation.coordinate=currentLocation.coordinate;
_map.showsUserLocation=YES;
}
this code works but let me tell you how
if i set the location in simulator to none nothing happen when i trigger the action.
if i set the location to any of the given option lets just say apple it will show location of the apple and when i trigger the action the location that i give just showed for once like a second and than again the location of the apple is showed.
soo anyone who can help me out will be truly appreciated and my apologies to everyone to whom the question seem inappropriate.
Sometimes the location services on simulator are affected because of API key you are using. Your must have a look of this link firstly and follow the steps in order to implement google map in iOS.
Use following code to get user current location.
CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager requestWhenInUseAuthorization];
Save latitude & longitude accordingly.
float latitude = locationManager.location.coordinate.latitude;
float longitude = locationManager.location.coordinate.longitude;
Now you can navigate user location programatically using this method
- (IBAction)showMyLocation:(id)sender {
CLLocationCoordinate2D centre;
centre.latitude = latitude; // getting latitude
centre.longitude = longitude; // getting longitude
// IF USING MkMapView
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(centre, 200, 200)];
[self.mapView setRegion:adjustedRegion animated:YES];
// IF USING GMSMapView
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
[self.mapView animateToCameraPosition:camera];
}
Note: add these tow keys NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription into your project's info.plist file before see image below.
You can use this AppleScript to open the simulator and set the location automatically:
tell application "Simulator"
activate
end tell
tell application "System Events"
tell process "Simulator"
tell menu bar 1
tell menu bar item "Debug"
tell menu "Debug"
tell menu item "Location"
click
tell menu "Location"
click menu item "Custom Location…"
end tell
end tell
end tell
end tell
end tell
tell window 1
set value of text field 1 to "52,625"
set value of text field 2 to "13,51"
click button "OK"
end tell
end tell
end tell
I used run-applescript to run AppleScript inside my javascript code.
runApplescript('tell application "Simulator" \nactivate\nend tell\ntell application "System Events"\ntell process "Simulator"\ntell menu bar 1\ntell menu bar item "Debug"\ntell menu "Debug"\ntell menu item "Location"\nclick\ntell menu "Location"\nclick menu item "Custom Location…"\nend tell\nend tell\nend tell\nend tell\nend tell\ntell window 1\nset value of text field 1 to "52,625"\nset value of text field 2 to "13,51"\nclick button "OK"\nend tell\nend tell\nend tell')
PS: You need to give permission to terminal. (System Preferences -> Security & Privacy -> Privacy tab -> Select Accessibility on the left menu -> select terminal on the list)
Is there one way to customize myLocationButton GoogleMaps ? I want to add my own button with a background image which make the same function as the original Google button
First your Application needs to get current location using CLLocation Manager. If you don't know how, refer to my answer here : For google maps iOS sdk, current location occasionally gets plotted at 0,0
Now for button press action, do this
- (void)locationButtonPressed
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.mapView.myLocation.coordinate.latitude
longitude:self.mapView.myLocation.coordinate.longitude
zoom:self.mapView.camera.zoom];
[self.gMapView animateToCameraPosition:camera];
}
Hope that helps.
In the application I have some mapViews, and I want to support offline mode(caching). So: user installed app, the main screen contains mapView and it should cache it. Then user turns off the Wi-Fi and 3G, and tries to take a look at another mapView ( another viewController). It's not downloaded now. But the main screen's map is okay. Am I in the wrong way to cache?
the code for configuring the map is the same:
[[RMConfiguration sharedInstance] setAccessToken:#"pk.***"];
RMMapboxSource *tileSource = [[RMMapboxSource alloc] initWithMapID:kMapboxMapID];
[tileSource setCacheable:YES];
[self.mapView.tileCache setBackgroundCacheDelegate:self];
[self.mapView.tileCache beginBackgroundCacheForTileSource:tileSource southWest:CLLocationCoordinate2DMake(55.767363, 37.592843) northEast:CLLocationCoordinate2DMake(55.799801, 37.671229) minZoom:11 maxZoom:11];
self.mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:tileSource];
self.mapView.delegate=self;
[self.view addSubview:self.mapView];
If you aren't using RMTileCache's download methods to pre-fetch an area of the map, this will only work if the map area trying to be viewed in the second view controller is the same as that already viewed in the first.
I'm having problems taking the first few steps with MapBox iOS SDK (1.4.1).
I've started with the suggested code over here: https://www.mapbox.com/mapbox-ios-sdk/examples/
- (void)viewDidLoad {
[super viewDidLoad];
self.mapBoxView.tileSource = [[RMMapboxSource alloc] initWithMapID:#"my_map_id" enablingDataOnMapView:_mapBoxView];
self.mapBoxView.userTrackingMode = RMUserTrackingModeNone;
CLLocationCoordinate2D centerLocation;
centerLocation.latitude = NRMapStartLatitude;
centerLocation.longitude = NRMapStartLongitude;
[self.mapBoxView setCenterCoordinate:centerLocation];
[self.mapBoxView setZoom:7 animated:YES];
}
No matter what I do the map starts at a location in Washington D.C. but I've set the center coordinate to be somewhere in Europe.
The same with the zoom. No matter what value I try it has no effect on the map.
There's something with the NSLog output that confuses me. At startup it says:
Using watermarked example map ID examples.map-z2effxa8. Please go to
https://mapbox.com and create your own map style.
I was assuming that this is something that I already did by registering for a free account there and starting with my first project.
Added the tilesource 'My First Map' to the container
Origin is calculated at: 120.786199, -85.000000 Map initialised. tileSource:RMMapboxSource:
Mapbox iOS Example, zooms 0-19, no interactivity, minZoom:2.000000, maxZoom:18.000000,
zoom:18.000000 at {-77.032458,38.913175}
Apparently the sample project in the iOS SDK is loaded and ignoring everything else I try to configure.
So, how do I configure the map so I can interact with the API. What am I missing?
Any kind of help is highly appreciated. Thank you!
OK, whoever is struggling with that. The trick is to set the zoom BEFORE you set the center coordinate..
..for whatever reason.
I need to display a map without street names. is it possible using MKMapView ? if not, is there a different map API for iOs that supports this?
thanks,
Nimrod
What you need to do, is to set the maptype to Satellite.
Here's how to do this:
[mapView setMapType:MKMapTypeSatellite];
EDIT:
Not sure if it's satellite, but try one of these:
[mapView setMapType:MKMapTypeStandard];
[mapView setMapType:MKMapTypeHybrid];
[mapView setMapType:MKMapTypeSatellite];
Nimrod, you can't show the map view hiding the street name, only showing the Satellite view. However, check the Google Maps SDK - they just launched it and they provide a lot of thinks that the default MKMapView don't provide.
The MapBox iOS SDK will allow you to customize your map completely, including removing street names, but with MapKit-like functionality.
If you prefer, you can use the Google Maps SDK and make a custom map in this link:
http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html?utm_medium=twitter
And then use the atributes generated in this to custom your map in the app.