Skip to content

Instantly share code, notes, and snippets.

@gimdongwoo
Last active May 24, 2016 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gimdongwoo/b0f40728bb1bf5a3aa7ede3e2443aa10 to your computer and use it in GitHub Desktop.
Save gimdongwoo/b0f40728bb1bf5a3aa7ede3e2443aa10 to your computer and use it in GitHub Desktop.
Google Maps in Titanium Webview
<!-- 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>
/**
* 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