teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コード追記

2016/09/27 15:27

投稿

imamoto_browser
imamoto_browser

スコア1161

title CHANGED
File without changes
body CHANGED
@@ -39,4 +39,31 @@
39
39
  30 </head>
40
40
  ```
41
41
 
42
- 上記のlocation.jsに書いて呼んでます。
42
+ 上記のlocation.jsに書いて呼んでます。
43
+
44
+ location.js
45
+ ```javascript
46
+ 1 var map = new google.maps.Map(
47
+ 2 document.getElementById("gmap"),{
48
+ 3 zoom : 15,
49
+ 4 center : new google.maps.LatLng(35.689160610317174, 139.70083951950073),
50
+ 5 mapTypeId : google.maps.MapTypeId.ROADMAP
51
+ 6 }
52
+ 7 );
53
+ 8
54
+ 9 var ll = map.getCenter();
55
+ 10 var gc = new google.maps.Geocoder();
56
+ 11 gc.geocode({ location : ll }, function(results, status){
57
+ 12 if (status == google.maps.GeocoderStatus.OK) {
58
+ 13 var adrsData = results[0].address_components;
59
+ 14 var txt = "";
60
+ 15 for(var i=0; i<adrsData.length; i++){
61
+ 16 txt += adrsData[i].long_name + " / ";
62
+ 17 txt += adrsData[i].types + "<br>";
63
+ 18 }
64
+ 19 document.getElementById("result").innerHTML = txt;
65
+ 20 }else{
66
+ 21 alert(status+" : ジオコードに失敗しました");
67
+ 22 }
68
+ 23 });
69
+ ```

1

追記

2016/09/27 15:27

投稿

imamoto_browser
imamoto_browser

スコア1161

title CHANGED
File without changes
body CHANGED
@@ -13,4 +13,30 @@
13
13
  7 );
14
14
  ```
15
15
 
16
- 上記箇所が原因なのは特定できたのですが、どのように書き換えるべきでしょうか。(ただ、このソースを載せている[ページ](http://www.openspc2.org/reibun/Google/Maps/API/ver3/code/map/geocoding/0003/)のサンプルは動いているので、APIのkeyに問題があるような気はするのですが、その認識で合ってますでしょうか。)
16
+ 上記箇所が原因なのは特定できたのですが、どのように書き換えるべきでしょうか。(ただ、このソースを載せている[ページ](http://www.openspc2.org/reibun/Google/Maps/API/ver3/code/map/geocoding/0003/)のサンプルは動いているので、APIのkeyに問題があるような気はするのですが、その認識で合ってますでしょうか。)
17
+
18
+ 追記:
19
+ ```html
20
+ <head>
21
+ 12 <title>hoge</title>
22
+ 13
23
+ 14
24
+ 15 <link rel="canonical" href="/link">
25
+ 16
26
+ 17
27
+ 18 <link rel="icon" type="image/x-icon" href="/moge/assets/default/img/common/favicon.ico" />
28
+ 19
29
+ 20 <link rel="stylesheet" type="text/css" href="hoge.css">
30
+ 21 <link rel="stylesheet" type="text/css" media="print" href="moge.css">
31
+ 22 <script src="http://maps.google.com/maps/api/js?key=mykey&sensor=false"></script>
32
+ 23 <script src="http://fb.me/react-0.13.3.js"></script>
33
+ 24 <script src="http://fb.me/JSXTransformer-0.13.3.js"></script>
34
+ 25 <script data-require="angular.js@1.2.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js" data-semver="1.2.17"></script>
35
+ 26 <script src="app.js"></script>
36
+ 27 <script src="hoge.js"></script>
37
+ 28 <script src="location.js"></script>
38
+ 29
39
+ 30 </head>
40
+ ```
41
+
42
+ 上記のlocation.jsに書いて呼んでます。