I used GMSMapView for iOS app. I want to remove default marker/annotation from GMSMapView but it's not removed. I use maptype property to remove it which is working perfect in Android but in iOS it's not working. Let me share code sample here.
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: zoom)
mapView = GMSMapView.map(withFrame: rect, camera: camera)
mapView.mapType = .terrain //<--- it's not working somehow in code i have tried all options.
Is there any other way to remove all default marker/annotation from GMSMapView in iOS?
Let me attached image for visibility.
screen shot of issue
Please Refer this ans i have tested its working
iOS Google Maps SDK - Hide / remove labels
first add myStyle.json file in your project and then call the do catch
You need to customize the map's style and you can do that with a JSON file in the app's bundle. Those markers are POI markers and you can remove them entirely with the following:
[
{
"featureType": "poi",
"stylers": [
{
"visibility": "off"
}
]
}
]
JSON generator: https://mapstyle.withgoogle.com/
API reference: https://developers.google.com/maps/documentation/ios-sdk/style-reference
Related
In my iOS app I'm using GoogleMaps and APIs for maps and I'm not very familiar with it.
I know that with iOS native MKMapView you can set a visible map rect to fit all the points needed at a proper zoom level, like described here: Zooming MKMapView to fit annotation pins?
but I'm not sure how to do such thing for GMSMapView. Does anyone know how to do it?
Any kind of help is highly appreciated!
Add this after setting up markers on the Map:
var bounds = GMSCoordinateBounds()
for coordinate in testCoordinates {
bounds = bounds.includingCoordinate(coordinate)
}
let update = GMSCameraUpdate.fit(bounds, withPadding: 50)
mapView.animate(with: update)
So basically I want to use an SVG file I drew as an overlay for the Google Maps iOS API 3. Whenever I use a .jpg file it seems to work fine. I'm using iOS 12
I've tried switching file names and it still only seems to work with JPEGS, not sure about PNGS.
This is my code:
let camera = GMSCameraPosition.camera(withLatitude: 47.457925, longitude: 8.548466, zoom: 16.0)
let southWest = CLLocationCoordinate2D(latitude: 47.444561, longitude: 8.534752)
let northEast = CLLocationCoordinate2D(latitude: 47.483037, longitude: 8.575470)
let overlayBounds = GMSCoordinateBounds(coordinate: southWest, coordinate: northEast)
let icon = UIImage(named: "lszh-int-lv-main.svg")
let overlay = GMSGroundOverlay(bounds: overlayBounds, icon: icon)
overlay.bearing = 0
overlay.map = mapView
mapView.camera = camera
mapView.animate(to: camera)
I'm not getting any error messages with the SVG, it's just not showing up. Is it impossible to even show SVGs as overlays? Thank you for your help!
Preserve Vector Data
Xcode 9 changes this situation by allowing you to choose to treat the image as a vector at runtime. This means the image can smoothly
scale to arbitrary sizes. The only change you need to make is to tick
Preserve Vector Data for the PDF image in the asset catalog.
You need to export your vector as an pdf and add it into asset catalog. For more info :
Link 1 Link 2
I'm trying to use Google Maps SDK to display a map of my current location (Berkeley, CA) as the focus, but regardless of what lat/lon I put in, it always shows Europe, as shown below:
Here is the code for the map view:
let camera = GMSCameraPosition.cameraWithLatitude(37.8750360, longitude: -122.2573240, zoom: 1)
mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
mapView.delegate = self
I'm doing very similar things in other parts of my application, but have never gotten an issue. If someone knows how to fix this, please let me know! Thanks
Please make sure that you are test on real device. not be Simulator,
If you use Simulator than enter latitude and longitude manually.
Like this-
You can test is on simulator as well and you can change location without enter lat-long
for that you need to change location from your Xcode (above console Please rifler the below screen shot
)
Maybe this is because you are setting the mapView's frame to CGRectZero. This may cause the map to have zero height and zero width.
Example based from this tutorial:
override func viewDidLoad()
{
let camera: GMSCameraPosition = GMSCameraPosition.cameraWithLatitude(37.8750360, longitude: -122.2573240, zoom: 1)
mapView = GMSMapView.mapWithFrame(self.view.frame, camera: camera)
mapView.camera = camera
}
Check these related questions:
Current Location in Google Maps with swift
Show GoogleMaps on View in Swift?
You're setting up your view before even setting your delegate (so your code isn't even attached to your instance of mapView). Fix it like this:
1: Make sure you've defined your GMSMapViewDelegate for the class
2: Set your delegates first
mapView.delegate = self
mapView.myLocationEnabled = true
let camera = GMSCameraPosition.cameraWithLatitude(37.8750360, longitude: -122.2573240, zoom: 1)
mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
Is there an official way to set a custom user location dot in Google maps for iOS (GMSMapView)?
Is there a known way to "hack" it? Like iterating through all subviews and layers and fish the blue dot?
Even if you can't customise its appearance, can you control its z order index? When you have many markers, the little blue dot becomes hidden, and sometimes you want it to be visible at all times.
Thanks
You can try to find the image on:
GoogleMaps.framework > Resources > GoogleMaps.bundle
OR
GoogleMaps.framework > Resources > GoogleMaps.bundle > GMSCoreResources.bundle
I did a quick search on those and the only associated file I found with that blue dot is GMSSprites-0-1x.
Please read the google maps terms and conditions because this might not be legal.
You can set the maps myLocationEnabled to NO. That will hide the default location dot. Then use an instance of CLLocationManager to give you your position. Inside CLLocationManager didUpdateLocations method you can set a custom GMSMarker. Set its icon property to whatever you want your dot to look like using [UIImage imageNamed:]. This will allow you to achieve the desired effect.
Swift 4
Disable the default Google Map current location marker (it's disabled by default):
mapView.isMyLocationEnabled = false
Create a marker as an instance property of the view controller (because a delegate will need access to this):
let currentLocationMarker = GMSMarker()
The GMSMarker initializer allows for a UIImage or a UIView as a custom graphic, not a UIImageView unfortunately. If you want more control over the graphic, use a UIView. In your loadView or viewDidLoad (wherever you configured the map), configure the marker and add it to the map:
// configure custom view
let currentLocationMarkerView = UIView()
currentLocationMarkerView.frame.size = CGSize(width: 40, height: 40)
currentLocationMarkerView.layer.cornerRadius = 40 / 4
currentLocationMarkerView.clipsToBounds = true
let currentLocationMarkerImageView = UIImageView(frame: currentLocationMarkerView.bounds)
currentLocationMarkerImageView.contentMode = .scaleAspectFill
currentLocationMarkerImageView.image = UIImage(named: "masterAvatar")
currentLocationMarkerView.addSubview(currentLocationMarkerImageView)
// add custom view to marker
currentLocationMarker.iconView = currentLocationMarkerView
// add marker to map
currentLocationMarker.map = mapView
All that remains is giving the marker a coordinate (initially and every time the user's location changes), which you do through the CLLocationManagerDelegate delegate.
extension MapViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let lastLocation = locations.last!
// update current location marker
currentLocationMarker.position = CLLocationCoordinate2D(latitude: lastLocation.coordinate.latitude, longitude: lastLocation.coordinate.longitude)
}
}
The first few locations that the location manager produces may not be very accurate (although sometimes it is), so expect your custom marker to jump around a bit at first. You can wait until the location manager has gathered a few coordinates before applying it to your custom marker by waiting until locations.count > someNumber but I don't find this approach very attractive.
I am trying to use the MapKit-Framework in iOS. I have a map, where I draw a polyline.
Now I want to add some simple annotations. I add them to the map, but they are not shown directly. I have to move the camera. After I move the camera or use the zoom, the annotations are visible.
What I have to call to refresh the map to show the annotations directly?
var zugEndeAnnotation : MKPointAnnotation = MKPointAnnotation();
zugEndeAnnotation.coordinate = CLLocationCoordinate2D(latitude: zugEnde.coordinate.latitude , longitude: zugEnde.coordinate.longitude);
self.map.addAnnotation(zugEndeAnnotation);
best regards