Created
March 18, 2014 20:24
-
-
Save wf9a5m75/9628734 to your computer and use it in GitHub Desktop.
マーカーを表示する:Google Maps Mobile SDK / Cordova(PhoneGap) ref: http://qiita.com/wf9a5m75/items/15970e0dd289939082ed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var GOOGLE, GOOGLE_TOKYO, GOOGLE_SYDNEY; | |
document.addEventListener("deviceready", function() { | |
//位置を定義 | |
GOOGLE = new plugin.google.maps.LatLng(37.422858, -122.085065); | |
GOOGLE_TOKYO = new plugin.google.maps.LatLng(35.660556,139.729167); | |
GOOGLE_SYDNEY = new plugin.google.maps.LatLng(-33.867487,151.20699); | |
//地図を作成 | |
var map = plugin.google.maps.Map.getMap(); | |
//地図の初期化完了を待つ | |
map.addEventListener(plugin.google.maps.MAP_READY, onMapReady); | |
}, false); | |
function onMapReady(map) { | |
//マーカーを追加する | |
map.addMarker({ | |
"position": GOOGLE, | |
"title": "Hello GoogleMap for Cordova!" | |
}); | |
//地図を表示する | |
map.showDialog(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//マーカーを追加する | |
map.addMarker({ | |
"position": GOOGLE, | |
"title": "Hello GoogleMap for Cordova!" | |
}, function(marker) { | |
//マーカーが地図に追加されたので、情報ウィンドウを表示する | |
marker.showInfoWindow(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marker.addEventListener(plugin.google.maps.event.MARKER_CLICK, function() { | |
marker.showInfoWindow(); | |
}); | |
marker.addEventListener(plugin.google.maps.event.INFO_CLICK, function() { | |
marker.hideInfoWindow(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.addMarker({ | |
'position': GOOGLE_TOKYO, | |
'title': 'Google Tokyo!' | |
'icon': 'www/images/google_tokyo_icon.png' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.addMarker({ | |
'position': GOOGLE_TOKYO, | |
'title': 'Google Tokyo!', | |
'icon': { | |
'url': 'www/images/google_tokyo_icon.png', | |
'size': { | |
'width': 74, | |
'height': 126 | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.getElementById("canvas"); | |
map.addMarker({ | |
'position': GOOGLE_TOKYO, | |
'title': canvas.toDataURL(), | |
'icon': "data:image/png;base64,iVBORw0KGgoA...", | |
}, function(marker) { | |
marker.showInfoWindow(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.addMarker({ | |
'position': GOOGLE_SYDNEY, | |
"title": "Hello Google Maps" | |
}, function(marker) { | |
marker.addEventListener(plugin.google.maps.event.MARKER_CLICK, function() { | |
alert("マーカーがクリックされた"); | |
//情報ウィンドウの表示 | |
marker.showInfoWindow(); | |
}); | |
marker.addEventListener(plugin.google.maps.event.INFO_CLICK, function() { | |
alert("情報ウィンドウがクリックされた"); | |
//マーカーを削除 | |
marker.remove(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GOOGLE = new plugin.google.maps.LatLng(37.422858, -122.085065); | |
map.addMarker({ | |
'position': GOOGLE, | |
'draggable': true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.addMarker({ | |
'position': GOOGLE | |
}, function(marker) { | |
marker.setDraggable(true); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map.addMarker({ | |
'position': GOOGLE, | |
'draggable': true | |
}, function(marker) { | |
marker.addEventListener(plugin.google.maps.event.MARKER_DRAG_END, function(marker) { | |
marker.getPosition(function(latLng) { | |
marker.setTitle(latLng.toUrlValue()); | |
marker.showInfoWindow(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GOOGLE = new plugin.google.maps.LatLng(37.422858, -122.085065); | |
map.addMarker({ | |
'position': GOOGLE, | |
'flat': true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment