Last active
May 24, 2016 22:56
-
-
Save gimdongwoo/b0f40728bb1bf5a3aa7ede3e2443aa10 to your computer and use it in GitHub Desktop.
Google Maps in Titanium Webview
This file contains hidden or 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
<!-- app/assets/html/GMapsSingle.html --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> | |
<meta charset="utf-8"> | |
<title>GMapsSingle</title> | |
<style> | |
html, body { | |
height: 1920px; | |
margin: 0; | |
padding: 0; | |
} | |
#map { | |
height: 1920px; | |
} | |
</style> | |
<script src="https://maps.googleapis.com/maps/api/js?key=***API_KEY***&v=3.exp&signed_in=false"></script> | |
<script> | |
window.onresize= function (){ | |
document.getElementById("map").style.height = window.innerHeight + 'px'; | |
}; | |
function onloadInitMap(params) { | |
var singleLatLng = new google.maps.LatLng(params.latitude, params.longitude); | |
initMap(singleLatLng); | |
} | |
// This example adds a marker to indicate the position of Bondi Beach in Sydney, | |
// Australia. | |
function initMap(singleLatLng) { | |
var map = new google.maps.Map(document.getElementById('map'), { | |
center: singleLatLng, | |
zoom: 15, | |
disableDefaultUI: true | |
}); | |
var pinIcon = new google.maps.MarkerImage( | |
"http://***********/images/map_mappin.png", | |
null, /* size is determined at runtime */ | |
null, /* origin is 0,0 */ | |
null, /* anchor is bottom center of the scaled image */ | |
new google.maps.Size(88, 88) | |
); | |
var singleMarker = new google.maps.Marker({ | |
position: singleLatLng, | |
map: map, | |
icon: pinIcon | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="map"></div> | |
</body> | |
</html> |
This file contains hidden or 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 view show | |
*/ | |
var loadingPlugin = { show: function(){}, hide: function() {} }; | |
var webView = {}; | |
var mapViewShow = function (_location) { | |
Ti.API.debug('debug', 'mapViewShow', _location); | |
webView = Titanium.UI.createWebView({ | |
url: '/html/GMapsSingle.html', | |
width: '100%', | |
height: '99%', | |
top: 0 | |
}); | |
// webview need resize event for height define | |
loadingPlugin.show(); | |
webView.addEventListener('load',function (e) { | |
webView.removeEventListener('load', arguments.callee); | |
webView.height = '100%'; | |
webView.evalJS("onloadInitMap("+ JSON.stringify(_location) +")"); | |
loadingPlugin.hide(); | |
}); | |
$.mainView.add(webView); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment