質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

Q&A

解決済

2回答

2934閲覧

SwiftでGoogleMapを使う際に初期位置が指定できない

Dai04

総合スコア5

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

0グッド

1クリップ

投稿2019/12/02 14:40

swiftにgooglemapを表示させたいのですが、それをUILabel上に表示させようとすると、初期位置がLondonとなってしまい、指定した位置となってくれません。(画面全体に表示させると指定した初期位置を表示してくれます。)ちなみに指定している位置はシドニーです。

swift

1 2import UIKit 3import GoogleMaps 4 5class ViewController: UIViewController { 6 7 @IBOutlet weak var myMapView: UIView! 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 // Do any additional setup after loading the view. 11 12 GMSServices.provideAPIKey("APIキー") 13 //let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0) 14 //let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 15 let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0) 16 let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 17 mapView.isMyLocationEnabled = true 18 mapView.settings.myLocationButton = true 19 self.myMapView = mapView 20 21 // Creates a marker in the center of the map. 22 let marker = GMSMarker() 23 marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20) 24 marker.title = "Sydney" 25 marker.snippet = "Australia" 26 marker.map = mapView 27 } 28 29 30}

self.myMapView = mapViewが画面全体に表示するview = mapViewだとうまくいくのですが、この状態だと上記のような状況になってしまいます。。。どうしてもUIView上に表示させたいので、どなたかご教授お願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takabosoft

2019/12/03 01:35

このコードで地図って表示されるんでしょうか?見た感じ真っ白になりそうな気がするのですが・・・
Dai04

2019/12/03 05:27

ViewController上のUIViewには地図を表示させることはこのコードでできましたが、シドニーではなく、初期位置がLondonになってしまいます。。。
takabosoft

2019/12/03 07:06

載せてもらったコードだけだと、 self.myMapView = mapView というようにmapViewをメンバ変数に代入しているだけであって、画面に表示するコードが全く無いような気がするのですが、何故画面に出るんでしょう??
guest

回答2

0

ベストアンサー

ちなみにrepoを更新しました。
UIViewを使って、GoogleMapを表示しています。
地図の上には、簡単た検索のフォームも追加しました。APIにつながってなくて、とりあえずDictionaryに格納した"Moscow", "New York", "London"を検索できる。

イメージ説明

投稿2019/12/03 06:50

vanderlvov

総合スコア685

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

公式なチュートリアルに従って実装してみて、ちゃんと「シドニー」が出てきました。
サンプルプロジェクトを作りました:https://github.com/vanderlvoff/mapApp

@IBOutlet weak var myMapView: UIView!などが必要ないと思います。

AppDelegate.swift:

Swift

1// 2// AppDelegate.swift 3// mapApp 4// 5// Created by My Name on 2019/12/03. 6// Copyright © 2019 My Name. All rights reserved. 7// 8 9import UIKit 10import GoogleMaps 11 12@UIApplicationMain 13class AppDelegate: UIResponder, UIApplicationDelegate { 14 15 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 // Override point for customization after application launch. 17 GMSServices.provideAPIKey("{API_KEY}") 18 return true 19 } 20 21 // MARK: UISceneSession Lifecycle 22 23 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 // Called when a new scene session is being created. 25 // Use this method to select a configuration to create the new scene with. 26 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 } 28 29 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { 30 // Called when the user discards a scene session. 31 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 } 34 35 36} 37

ViewController.swift:

Swift

1import UIKit 2import GoogleMaps 3 4class ViewController: UIViewController { 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 // Do any additional setup after loading the view. 9 10 // Create a GMSCameraPosition that tells the map to display the 11 // coordinate -33.86,151.20 at zoom level 6. 12 let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0) 13 let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 14 view = mapView 15 16 // Creates a marker in the center of the map. 17 let marker = GMSMarker() 18 marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20) 19 marker.title = "Sydney" 20 marker.snippet = "Australia" 21 marker.map = mapView 22 } 23}

投稿2019/12/03 03:17

vanderlvov

総合スコア685

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Dai04

2019/12/03 05:25

ViewController上のUIViewに地図を配置したく、その場合に初期位置がLondonに固定されてしまうのですが、その場合はどのようにしたら良いのでしょうか?
vanderlvov

2019/12/03 05:41

ああ、なるほど、そうすると時間ください。この間、誰かが回答してくれるか、僕は夜にやってみますね。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問