ArcGIS iOS Map does not pan or zoom - ios

I am walking through the basic iOS guide to add a map to my App here: https://developers.arcgis.com/ios/10-2/swift/guide/develop-your-first-map-app.htm
When running the app, it displays the basemap I have added but it does not seem to respond to any actions so I can not pane/zoom.
Here is my exact Swift controller code:
import UIKit
import ArcGIS
class ViewController: UIViewController, AGSMapViewLayerDelegate {
#IBOutlet var mapView: AGSMapView!
override func viewDidLoad() {
super.viewDidLoad()
let tiledLayer = AGSLocalTiledLayer(name: "Norfolk")
self.mapView.addMapLayer(tiledLayer, withName: "Norfolk")
mapView.locationDisplay.startDataSource()
}
}
I have tested on both an iPad and iPhone and the behavior is the same.
I am using ArcGIS 10.2.5

Where is your map url?
let url = NSURL(string: "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer")
let tiledLayer = AGSTiledMapServiceLayer(URL: url)
self.mapView.addMapLayer(tiledLayer, withName: "Basemap Tiled Layer")
And have you added Privacy - Location When In Use Usage Description into info.plist of your app? You should do that if you call
mapView.locationDisplay.startDataSource()

I am not sure what I did incorrectly the first time, but I removed the view and re added it and it worked the 2nd time.

Related

Google Maps GMSPanoramaView api blocked

I'm getting this error:
This application has been blocked by the Google Maps API. This might be because of an incorrectly registered key.
When I try to set google maps panorama street view. If I display a regular map view, it works so seems like the key is registered properly.
I followed the directions for a panorama view exactly as per google docs:
import UIKit
import GoogleMaps
class ViewController: UIViewController, GMSMapViewDelegate {
override func loadView() {
let panoView = GMSPanoramaView(frame: .zero)
self.view = panoView
panoView.moveNearCoordinate(CLLocationCoordinate2D(latitude: -33.732, longitude: 150.312))
}
}
Any ideas?
For me, the solution was that I needed to link my project in Google Cloud Platform to a billing account.
Once I did that the street view started working correctly.
The standard Google map worked fine without a billing account, which confused me initially.
You need to configure the delegate for this object. Something like:
import UIKit
import GoogleMaps
class ViewController: UIViewController, GMSMapViewDelegate {
override func loadView() {
let panoView = GMSPanoramaView(frame: .zero)
panoView.delegate = self
self.view = panoView
panoView.moveNearCoordinate(CLLocationCoordinate2D(latitude: -33.732, longitude: 150.312))
}
}
extension ViewController: GMSPanoramaViewDelegate {
func panoramaView(_ view: GMSPanoramaView, error: Error, onMoveNearCoordinate coordinate: CLLocationCoordinate2D) {
print("error: \(error.localizedDescription)")
}
}

Enable zooming in WKWebView in Swift 4, Xcode 10, for iOS 12

I am trying to enable zooming/magnification (by pinching) in a very simple WebView in a simple app. (I am pretty new to this).
The Swift code that loads the web page is this and it works fine, I got from here, I think.
import UIKit
import WebKit
class SecondViewController: UIViewController {
#IBOutlet weak var WebViewSchedule: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// load the page
let url = URL(string: "https://mywebsite.com")
let request = URLRequest(url: url!)
WebViewSchedule.load(request)
//how do i make it zoomable ????
}
}
I've looked at a number of answers about this, and they all refer to a property "allowsMagnification". I have tried various ways of using this and got nowhere.
So could some kind person give me a beginners' guide to how to make my iOS Web page zoomable?

Swift Error : Classes implemented in two places but files I don't touch?

I am testing out swifts UIWebView, I have placed a simple UIWebview on my storyboard and this is my viewController code
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL(string: "https://mywebsitehere.com")
webView.loadRequest(URLRequest(url: url!))
} }
Unfortunately I am getting this Error below, I have added App transport security settings to my app like other answers to a similar question have said to do but it still isn't working...
Can anyone help?
objc[946]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x124feecc0) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x124e056f0). One of the two will be used. Which one is undefined.
This is bug with xCode while simulating the real iOS device, some time it through such kind of error.
Please check whether your url is active or not.
let url = URL(string: "https://google.com")
webView.loadRequest(URLRequest(url: url!))
I used the same code with google URL and it is working.

WKWebView's (beta) takeSnapshot method, how to implement?

I noticed the WKWebView documentation now lists a method called takeSnapshot that is supported by iOS 11 and macOS 10.13 and above (Xcode 9 beta).
Has anyone played around with yet or implemented? I'm trying to get it working in a playground but I'm not sure where to start? Is this a method on a WKWebView?
My code:
import UIKit
import PlaygroundSupport
import WebKit
let frame = CGRect(x: 0, y: 0, width: 800, height:600)
let web = WKWebView(frame: frame)
let rq = URLRequest(url: NSURL(string: "http://apple.com")! as URL)
web.load(rq)
PlaygroundPage.current.liveView = web
PlaygroundPage.current.needsIndefiniteExecution = true
//Take snapshot?
As far as I tested, the method takeSnapshot(with:completionHandler:) actually exists as an instance method and works as expected.
Just that it's a little hard to use it.
The method declares its first parameter as WKSnapshotConfiguration?, but the class WKSnapshotConfiguration is not imported with import WebKit. You can pass nil to the parameter, but to use the method, you need to import the type WKSnapshotConfiguration. And I could not have found any dependent submodules to import WKSnapshotConfiguration.
So, if you want to play with this new feature, you need to create an App project with bridging-header.
(If you know how to use bridging-header in the Playground, you may test this feature in it. But I do not know if you can or how.)
{ProjectName}-Bridging-Header.h:
#import CoreGraphics;
#import <WebKit/WKSnapshotConfiguration.h>
And an example of ViewController.swift:
import UIKit
import WebKit
class ViewController: UIViewController {
#IBOutlet weak var webView: WKWebView!
#IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let request = URLRequest(url: URL(string: "http://apple.com")!)
webView.load(request)
}
#IBAction func buttonPressed(_ sender: UIButton) {
webView.takeSnapshot(with: nil) {image, error in
if let image = image {
self.imageView.image = image
print("Got snapshot")
} else {
print("Failed taking snapshot: \(error?.localizedDescription ?? "--")")
}
}
}
}
(Place a WKWebView, a UIImageView and a UIButton on a View.)
One more, this seems to be a bug of WebKit framework, you should better send a bug report to Apple.

Google maps Places Picker for iOS - GMSPlacePicker in Swift appearing but disappears when animation ends

I'm trying to convert the simple GMSPlacePicker example to Swift
but the Picker appears but then disappears immediately as soon as the transition from Right to left completes.
// ViewController.swift
import UIKit
import CoreLocation
import GoogleMaps
class ViewController: UIViewController {
#IBAction func buttonPlacesPicker_TouchUpInside(sender: AnyObject) {
//-----------------------------------------------------------------------------------
var southWestSydney : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-33.8659, 151.1953)
var northEastSydney : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-33.8645, 151.1969)
var sydneyBounds : GMSCoordinateBounds = GMSCoordinateBounds(coordinate: southWestSydney, coordinate:northEastSydney)
//var config : GMSPlacePickerConfig = GMSPlacePickerConfig(viewport:sydneyBounds)
var config : GMSPlacePickerConfig = GMSPlacePickerConfig(viewport:nil)
//---------------------------------------------------------------------
var placePicker : GMSPlacePicker = GMSPlacePicker(config: config)
//typealias GMSPlaceResultCallback = (GMSPlace?, NSError?) -> Void
var error: NSError? = nil
var gmsPlace: GMSPlace? = nil
placePicker.pickPlaceWithCallback(){
(gmsPlace, error) -> Void in
if let error = error{
println("error:\(error)")
}else{
if let gmsPlace = gmsPlace{
if let formattedAddress = gmsPlace.formattedAddress{
println("formattedAddress:\r\(formattedAddress)")
}else{
println("gmsPlace.formattedAddress is nil")
}
}else{
println("gmsPlace is nil")
}
println("info")
}
}
}
}
My app has asked for Location sucessfully
I have a bridging header to Google Maps.
I didnt use cocoa pods to install the framework
but I've used the framework in Obj-C before
so just dragged the GoogleMaps.framework to project
and the internal resources bundle
I added all the following from previous tutorials and linker errors:
When I run it I can see sydney in the pickers maps.
It transitions from right side fo the screen to the left.
When it reaches the left it disappears
I added Reveal app and I cant see the picker view offline.
My GMS services api key is correct as its one I used in obj-c app to show Places Picker.
Bundle id is correct.
My Swift knowledge is "I think I know it. I probably don't"
any ideas?
You should retain the reference to your GMSPlacePicker. Make it a property instead of local variable.
FIXED made it an ivar...DOH!
class ViewController: UIViewController {
var placePicker : GMSPlacePicker?
#IBAction func buttonPlacesPicker_TouchUpInside(sender: AnyObject) {
self.placePicker?.pickPlaceWithCallback(){
...

Resources