GMSMapView show blank map - ios

I add GMSMapView into my screen but I only can see my position icon and the marker i added. Why i cant see the road, building, etc?
Here is my code :
let camera = GMSCameraPosition.cameraWithLatitude(latitude,
longitude: longitude, zoom: 11.5)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
self.view = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(location.latitude, location.longitude)
marker.title = location.name
marker.snippet = location.address
marker.map = mapView
Any suggestion?

One of the main reason to have a blank map is that the key is not set properly
Did you set the API key correctly.
[GMSServices provideAPIKey:yourAPIKey];

I had the same issue and API key was correct. The reason was in this lines of code
[[NSUserDefaults standardUserDefaults] setValue:#"ru" forKey:#"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

Related

How to show a place-mark with specific angle information on Maps app (Apple Maps or Google Maps)?

I want to display Gunshot information on the Maps app. A gunshot has 2 main properties:
location - point from which the shot was fired
direction/angle - relative to Compass North
Using the following code snippet, I can open the Maps app with a specific place-mark.
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(gps_lat.doubleValue, gps_long.doubleValue);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:self.pUnit.unitLabel];
[mapItem openInMapsWithLaunchOptions:nil];
Is it possible to add angle/direction information along with the place mark? Basically the place-mark should rotate along with the map so as to clearly depict the direction of the gunshot.
you can achieve rotation of marker using google maps and rotation property of marker.
though you want obj-c code, my swift code will be helpful to understand you what I meant.
replace MARKER_IMAGE_NAME with your image
1) setup google map
let camera = GMSCameraPosition.camera(withLatitude: firstPoint.latitude,
longitude: firstPoint.longitude, zoom: 14)
let navHeight = (self.navigationController?.navigationBar.frame.size.height)! + 20
let frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height - navHeight)
let GMapView = GMSMapView.map(withFrame: frame, camera: camera)
self.view.addSubview(GMapView)
2) prepare marker
let bearing:Double = 90
var marker = GMSMarker()
marker.icon = UIImage(named: MARKER_IMAGE_NAME)
marker.appearAnimation = GMSMarkerAnimation.pop
3) apply rotation
marker.rotation = bearing
4) add marker to google map
marker.map = GMapView

Google Maps iOS SDK - Stop deselecting marker on map tap

I am adding a simple marker to my mapView, like so:
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(40.763981, -73.971647);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.map = self.mapView;
marker.snippet = #"My Marker";
self.mapView.selectedMarker = marker;
As you can see I select the marker upon placement, however I want to keep this marker selected, showing the infoview, at all times it is on the map.
Currently, if I tap elsewhere on the map, the infoview is hidden (but the marker stays)

Centering custom marker GMSMapView

I am trying to position my custom marker in iOS(Objective-C) with Google Maps.
Map view is all showing up fine with marker, however, moving the map will take the marker with it as its fetching current location. What I am looking for is the have it set to center of the map container, which will then fetch coordinates of map pin and display in search bar.
I am thinking I am doing this in reverse? I added the customer marker as a UIImage of the map container however it still does not show. Should I be getting the location from the position of the map marker, and then reverse geocoding address from there.
- (void)addPins:(float)lat andLng:(float)lng andName:(NSString*)strName withAddress:(NSString*)strAddr
{
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(currentUserLocation.coordinate.latitude, currentUserLocation.coordinate.longitude);
NSLog(#"lat : %f, lng : %f", lat, lng);
marker.icon = [UIImage imageNamed:#"map_pin"];
marker.title = strName;
marker.snippet = strAddr;
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView;
}
The user needs to be able to search and set their address, besides their current location.
Thanks
Use your mapView delegate and use the responder to re-center your pin and re-fire your geocoordinate lookup.
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
Edit: If GMS Maps does not have these delegates, the approach may work with using whatever [mapView didUpdate]callback they have documented.
You can set GMSCameraPosition for centering your marker
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:"YOUR LATITUDE"
longitude:"YOUR LONGITUDE"
zoom:centerZoom];
"YOUT GMSMAPVIEW" = [GMSMapView mapWithFrame:"YOUR VIEW".bounds camera:camera];

Swift. Google map view shows questionmarks instead of letters

Why is my google map view showing questionmarks instead of letters:
My code for implementing the map view:
let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.view = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
v1.8.0 (May 2014) has an update regarding an issue raised similar to you. The ticket raised suggests it may have something to do with the language settings. So, you can check out if the language setting was changed and hopefully it solves the issue. Also check if you're using the latest version of the Maps iOS SDK.

Remove markers from google maps iOS

I am building an iOS app using storyboards and Google Maps. Using iOS6
My application features the split view navigation as seen in the facebook app
On my left view I am selecting an item in a list which has lat/long cords and showing it on my map on the following method
- (void)viewWillAppear:(BOOL)animated
I would like to remove all markers in this method before I add another one (so only one marker is on the map), is there a way to do this? Below is my code to add a marker to the mapView
Thanks in advance - Jon
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:poi.lat
longitude:poi.lon
zoom:15];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;
mapView.mapType = kGMSTypeHybrid;
//Allows you to tap a marker and have camera pan to it
mapView.delegate = self;
}
-(void)viewWillAppear:(BOOL)animated
{
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(poi.lat, poi.lon);
options.title = poi.title;
options.snippet = poi.description;
options.icon = [UIImage imageNamed:#"flag-red.png"];
[mapView addMarkerWithOptions:options];
[mapView animateToLocation:options.position];
[mapView animateToBearing:0];
[mapView animateToViewingAngle:0];
}
To remove all markers
mapView.clear()
To remove a specific marker
myMarker.map = nil
To remove all markers simple do:
[self.mapView clear];
Please refer to the Google Map documentation: Google Maps SDK for iOS
Please refer to the section title "Remove a marker". Always check documentation for such methods.
mapView.clear()
// It will clear all markers from GMSMapView.
To remove a single marker from map.
yourMarkerName.map = nil
To remove all markers from map.
yourMapViewName.clear()
It's a little bit tricky here if you want to remove only one marker among a group of your markers.
let marker = GMSMarker(position: coordinate) //
marker.icon = UIImage(named: "ic_pin_marker")
marker.map = mapView
mapView.selectedMarker = marker // the specific marker you want to remove or modify by set it as selectedMarker on the map.
then you want to remove or modify
mapView.selectedMarker.map = nil //example to remove the marker form the map.
Hopefully useful with your condition.
mapView.clear() is not a good idea .
because The Places SDK for iOS enforces a default limit of 1,000 requests per 24 hour period.(If your app exceeds the limit, the app will start failing. Verify your identity to get 150,000 requests per 24 hour period.)
whit mapView.clear() the requests increase .
the best way is clear each marker and polylines .

Resources