jquery mobile - Keep Google Maps from reloading in JqueryMobile page -
i'm using google maps api in jquerymobile/phonegap project. if go map "page" , change zoom level, drag map around, etc , navigate away , map page doesnt save state, reloads map. have tried using dom-cache <div data-role="page" id="map" data-dom-cache="true">
didn't seem @ all.
how can save map "state" , avoid reload when navigating away , back?
requested code
<div data-role="page" id="map" data-dom-cache="true"> <div data-role="header" data-theme="e"> <h1>honeyspot</h1> </div> <div data-role="content" style="width:100%; height:100%; padding:0;"> <div id="map_canvas" style="width:100%;height:100%"></div> </div> <div data-role="footer" data-theme="a" data-id="mainnav" data-position="fixed"> <div data-role="navbar"> <ul> <li><a href="#top" data-icon="arrow-u" id="top">top</a></li> <li><a href="#add" data-icon="plus" id="add">add</a></li> <li><a href="#map" data-icon="search" id="search" class="ui-btn-active ui-state-persist">search</a></li> <li><a href="#feed" data-icon="bars" id="feed">feed</a></li> <li><a href="#profile" data-icon="gear" id="profile">profile</a></li> </ul> </div> <!-- /navbar --> </div> </div>
js
$(document).on('pageshow', '#map', function (event) { max_height(); navigator.geolocation.getcurrentposition(onsuccess, onerror,{'enablehighaccuracy':true,'timeout':20000}); }); function onsuccess(position) { var minzoomlevel = 15; var mylatlng = new google.maps.latlng(position.coords.latitude, position.coords.longitude); var map = new google.maps.map(document.getelementbyid('map_canvas'), { zoom: minzoomlevel, center: mylatlng, maptypecontrol: false, maptypeid: google.maps.maptypeid.roadmap }); }
thank leading me in right direction. changed $(document).ready(function(event) { , works great now!
Comments
Post a Comment