Unable to Add UI elements on top of AGSMapView - ios

I have an app that I'm trying to migrate from Google Maps to ArcGIS maps because I need to use the maps offline.
I'm using the ArcGIS iOS 100.6 SDK and am trying to place a UIbutton on top of AGSMapView. In the View Controller "MapView" and the UIButton are under "View". The UIbutton is not a subview of MapView. I also have three other elements that should overlay the map that I hide and unhide using "isHidden = true/false" and these cannot be displayed either. The app is written in Swift 4.2 and I'm using Xcode 10.3.
Here is the view in the view controller:
View
Safe Area
Btn Satellite Toggle (outlet name: "btnSatelliteToggle")
View Mark Location
View Verify Location
View Pic Detail
MapView
Constraints
This is the code where I show the map and try to add the button on top:
let viewMap = AGSMapView(frame: .zero)
viewMap.map = AGSMap(basemapType: .navigationVector,
latitude: currentLocation.latitude, longitude: currentLocation.longitude,
levelOfDetail: zoomLevel)
viewMap.graphicsOverlays.add(overlay)
viewMap.touchDelegate = self
view = viewMap
view.bringSubviewToFront(btnSatelliteToggle)
The map is displayed along with the graphics overlay, but I am unable to show any UI elements on top of the map. This works fine with Google maps, but not with ArcGIS maps.
How do I get these UI elements to be displayed on top of the AGSMapView generated map?
Thanks in advance for your help.

It appears your MapView is at the top of the view hierarchy and thus obscuring its sibling views.
Try rearranging the view hierarchy to place the MapView at the bottom:
View
Safe Area
MapView
Btn Satellite Toggle (outlet name: "btnSatelliteToggle")
View Mark Location
View Verify Location
View Pic Detail
Constraints

I actually just solved this. Here is the updated code that works:
viewMap.map = AGSMap(basemapType: .navigationVector,
latitude: currentLocation.latitude, longitude: currentLocation.longitude,
levelOfDetail: zoomLevel)
viewMap.graphicsOverlays.add(overlay)
viewMap.touchDelegate = self
I removed:
Setting AGSMapView(frame: .zero)
as this prevented the map from being displayed in MapView.
Also, by not setting a view (thus using the default view controller "view") all siblings are available for display and can be controlled via "isHidden."

Related

In IOS 13 Google Map camera position is not showing Accurate when ViewController is Presented not pushed.Both screenshot attached

I am working on Taxi App, Where I want to present and show three markers but always the camera position is always top left corner, I have to scroll map view to see the markers.Already tried these things.
Put my code in viewwillappear & viewdidappear and remove it from viewdidload.
Put all my code in DispatchQueue after 2 seconds
Use Animation & increase/Decrease time.
The sample code has been attached just to show one marker, which is perfectly working fine when view controller is being pushed to the navigation stack.
func testCode() {
mapView.layoutIfNeeded()
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
let camera = GMSCameraPosition(latitude: 31.326137, longitude: 75.575520, zoom: 10)
self.pickupMarker = GMSMarker()
self.addMarkerOnMap(lat: "31.326137", long: "75.575520", img: #imageLiteral(resourceName: "drop-icon"), mapVieww: self.mapView,marker: &(self.pickupMarker), title: "Drop at", snippet:"Hello")
CATransaction.begin()
CATransaction.setValue(Int(1), forKey: kCATransactionAnimationDuration)
self.mapView.animate(to: camera)
CATransaction.commit()
})
}
I did Four things to resolve this issue.
Take a container first where I want my map view, in the storyboard and make an outlet in the class.
Remove mapview outlet and remove mapview UIVIew from a storyboard also.
Programmatically add GMSMapView as a subview in a container (where I want to show the map).
Add code in viewdidappear method in Dispatchqueue and everything is now working fine.

How to add a fixed bar on the mapView on iOS

Recently, I have made a simple project which needs to use GoogleMap Api.
I think that my Question is so simple and easy,
but i don't know how to complete it.
Well this is my problem
i want to add a just simple bar on the View.(up 1, bottom 1)
these 2 bars are fixed. and also there is a button(like moving back button) on the bars that i can presse
Except 2 bar position, if i drag/swipe on mapView than change and show the location information.
please check the following image.(This is what i want to make.)
How can i put the bars on the view and let the bars can be seen in the simulator? plz let me know
(i dont upload code cuz it's not the problem about the code, just want to know about the concept of how to insert view(or layer?) like that)
First, let say you have a map view:
let camera = GMSCameraPosition.camera(withLatitude: 11.5449, longitude: 104.8922, zoom: 12)
let map = GMSMapView.map(withFrame: .zero, camera: camera)
map.isMyLocationEnabled = true
self.view = map
Then, you can just add your top and bottom views to the view as normal
let topBar = UIView()
view.addSubview(topBar)
let bottomBar = UIView()
view.addSubview(bottomBar)
And if you want to add other views such as texts and buttons, you can add them as subviews to the topBar or bottomBar view
let button = UIButton()
topBar.addSubview(button)
Noted: to put the views in the exact locations as in the image, you need to specify their locations.
For example:
bottomBar.frame = CGRect(x: 0, y: view.bounds.height - 200, width: view.bounds.width, height: 200)
In storyboard:
I didn't use google maps so here I'm using the default MKMapView as an example.
First, let's say we have a map view covering the entire view controller:
Then for the top bar, let's add a view and give it some constraints:
Now for the back button and the title:
Now, for the bottom bar: first we need a view to hold all the things:
For the texts, we use 4 uilabels, embed them into a stack to make them lined-up. Give some spacing as well to make them look good:
Finally, for the image on the right, we can use uiimageview or uibutton:
Don't forget to add constraints to the stackview and the uiimageview/uibutton

How to show MapKit compass?

Currently the compass only get's shown if a User applies a rotate-gesture. Otherwise the compass is hidden.
But it would be nice if my two wishes below were fulfilled!
Is it possible to display the compass always?
How to show / hide the compass-view using Swift?
You can do this quite easily in iOS 11 by using the new MKCompassButton class.
You need to create an instance of MKCompassButton and add it to your map view. You can then set its compassVisibility property to one of:
.visible - always visible
.never - never visible
.adaptive - the compasss is only visible if the map is rotated away from a North/up orientation.
If you keep a reference to the compass in a property you can change its visibility as you need:
mapview.showsCompass = false // Hide built-in compass
compassButton = MKCompassButton(mapView: mapview) // Make a new compass
compassButton.compassVisibility = .visible // Make it visible
mapview.addSubview(compassButton) // Add it to the view
// Position it as required
compassButton.translatesAutoresizingMaskIntoConstraints = false
compassButton.trailingAnchor.constraint(equalTo: mapview.trailingAnchor, constant: -12).isActive = true
compassButton.topAnchor.constraint(equalTo: mapview.topAnchor, constant: 12).isActive = true
Unfortunately, for prior versions of iOS there is no simple solution. I have seen suggestions that involve looking through the map view's subviews to try and find the compass view but there seems to be mixed results.

iOS Google Maps API - Views and Labels will not Overlay Over the Map

I have created a Google Map view using the Google Maps SDK for iOS and the map displays fine. Then I added a label on top of the Map. When I run this the label will not show on top of the map. I've tried moving the label to different positions, messing with constraints, but nothing seems to make the label show. I've also tried putting the label in the View instead of it being a child of Map. It still will not show.
Here is the relevant code:
import UIKit
import GoogleMaps
class MapViewController: UIViewController, GMSMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.cameraWithLatitude(37.4987309,
longitude: -77.4700891, zoom: 10)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.delegate = self
self.view = mapView
}
}
Here is the storyboard:
Try this. Drag a new view
into your storyboard and place it under your label like the picture.
Then CTRL+drag from the "Map View" to the "View" and shift+click the following options and click "add constraints"
This is simply setting the simple autolayout constraints. CTRL+drag the "Map View" into your view controller's class.
Replace self.view = mapView, with self.theMapView.addSubview(mapView).
(where theMapView is the "Map View" in the storyboard)
Now, instead of your actual main view adding the map as a view, you're just creating a subview that does the same, and you have full control of what goes on top of what!
I encountered the same situation and here is how I solved it.
In your storyboard you have a view named 'Map'
You created the following camera :
let camera = GMSCameraPosition.cameraWithLatitude(37.4987309,
longitude: -77.4700891, zoom: 10)
Control drag the 'Map' View onto your view controller and name it whatever, such as mapView
self.mapView.camera = camera
self.mapView.bringSubview(toFront: yourLabelToBePlacedOnTop)

how to move view from mapkit in xcode

I use mapkit framework in my app and I want move in my app with code not finger.
I create mapView and 4 buttons (up - bottom - left - right) that these buttons doing these works (go to top - go to bottom - ...) with code.
important notice : my friends I want moving specific part view (for example my specific part has 320px width and 100px height)
So I want when click top button my part (320*100) of my map move to top...
please guide me...
If each button moves to a static position (and zoom) on the map then you can create a configuration something like:
each button has an associated MKMapRect / MKCoordinateSpan
when a button is tapped, get the associated area information
call setVisibleMapRect:animated: on the map view
Note that you don't really need to think in terms of top / bottom, just specify exactly what area the map view should be displaying following selection of each button.
Alternatively, if the zoom level never changes, you can use setCenterCoordinate:animated:. Let's take this option for an example and using CLLocation to make life easy:
Create an array containing your locations:
configArray = #[ topLocation, bottomLocation, .... ];
Create the buttons, and set the tag of each to the appropriate array index:
topButton.tag = 0;
bottomButton.tag = 1;
...
When a button is tapped, get the tag to get the location to update the map:
CLLocation *location = self.configArray[sender.tag];
[self.mapView setCenterCoordinate:location.coordinate animated:YES];

Resources