-1

I am trying to add a google map to my android tablet to detect where the terminal is.But the map is not displayed completely. only a small part was displayed. and after rotate the screen, it can displayed perfectly. I did all this according to http://www.digitalnoiz.com/mobile-development/geolocation-jquery-mobile-maps/ This is my html code:

 <head>
        <link href='stylesheets/jquery.mobile-1.1.0.css' rel='stylesheet' />
        <link href='stylesheets/my.css' rel='stylesheet' />
        <script charset='utf-8' src='javascripts/jquery/jquery-1.7.1.min.js' type='text/javascript'></script>
        <script charset='utf-8' src='javascripts/jquery.ui.map.min.js' type='text/javascript'></script>
        <script charset='utf-8' src='http://maps.google.com/maps/api/js?sensor=true' type='text/javascript'></script>
        <script charset='utf-8' src='javascripts/application.js' type='text/javascript'></script>
        <script charset='utf-8' src='javascripts/jquery/jquery.mobile-1.1.1.js' type='text/javascript'></script>
    <script type="text/javascript" charset="utf-8" src="javascripts/phonegap/cordova-2.0.0.js"><\/script>
    </head>
    <body>
     <!-- Diagnostic -->
        <div data-role='page' id='diagnostic_page'>
          <div data-position='inline' data-role='header' data-theme='a'>
            <h2>
              Diagnostic
            </h2>
            <a data-icon='arrow-l' href='#index_page'>
              Back
            </a>
            <a data-role='button' href='#diagnostic_page' id='PageRefresh'>
              Refresh
            </a>
          </div>
          <div data-role='content' style='padding: 15px'>
            <ul data-divider-theme='a' data-inset='true' data-role='listview'>
             <!--there are some other list variables-->
              <li data-theme='c'>
                Show current location:
                <a class='classspan' href='#location_page'>
                  Click on me
                </a>
              </li>
            </ul>
          </div>
        </div>
        <!-- show current location -->
        <div data-role='page' data-theme='c' id='location_page'>
          <div data-position='fixed' data-role='header' data-theme='a'>
            <a data-icon='arrow-l' href='#diagnostic_page'>
              Back
            </a>
            <h2>
              DigitalNoiz
            </h2>
            <div data-role='header'></div>
            Geolocation
            <div id='map_canvas'></div>
            <div id='geolocation'></div>
          </div>
        </div>
     </body>

This is my Jquery code, all my function code are edited in application.js.

function onLoad() {
    console.log('Init reached');
    $.mobile.allowCrossDomainPages = true;
    $.mobile.showPageLoadingMsg();
    $.support.cors = true;
    document.addEventListener('deviceready', onDeviceReady, false);
}
function onDeviceReady() {
    console.log('Starting up...');
//  navigator.app.overrideBackbutton(true);
    document.addEventListener("backbutton", onBackKeyDown, false);
    console.log('Initializing db'); 
    refreshpage();
        getPosition();

}
function getPosition(){
    var geoOptions = { enableHighAccuracy: true, timeout: 10000 };
    navigator.geolocation.getCurrentPosition(function(position){ // geoSuccess
        // we have the position
        var geolocation = $('#geolocation');
        geolocation.html('<table></table>');

        var table = geolocation.find('table');
        if(position.coords.latitude)
            table.append('<tr><th>Latitude</th><td>' + position.coords.latitude + '</td></tr>');
        if(position.coords.longitude)
            table.append('<tr><th>Longitude</th><td>' + position.coords.longitude + '</td></tr>');
        if(position.coords.altitude)
            table.append('<tr><th>Altitude</th><td>' + position.coords.altitude + '</td></tr>');
        if(position.coords.accuracy)
            table.append('<tr><th>Accuracy</th><td>' + position.coords.accuracy + '</td></tr>');
        if(position.coords.altitudeAccuracy)
            table.append('<tr><th>Altitude Accuracy</th><td>' + position.coords.altitudeAccuracy + '</td></tr>');
        if(position.coords.heading)
            table.append('<tr><th>Heading</th><td>' + position.coords.heading + '</td></tr>');
        if(position.coords.speed)
            table.append('<tr><th>Speed</th><td>' + position.coords.speed + '</td></tr>');
        if(position.coords.timestamp)
            table.append('<tr><th>Timestamp</th><td>' + new Date(position.timestamp) + '</td></tr>');

         //show position on map 
        var map_canvas = $('#map_canvas');
        map_canvas.gmap(
            {'center' : position.coords.latitude + ',' + position.coords.longitude,
            'zoom' : 12,
            'disableDefaultUI':true,
            'callback':function(){
                var self = this; 
                var marker = self.addMarker({ 'position' : this.get('map').getCenter() });
                marker.click(function(){
                    self.openInfoWindow({ 'content' : 'This is your current location' }, this);
                });
            }
        }); 
    }, function(error){ // geoError
        navigator.notification.alert('error: ' + error.message + '\n' + 'code: ' + error.code);
    }, geoOptions);
}

Can anybody could give me some advices?

4

2 回答 2

0

Give your map div a size ( both width and height):

<div id='map_canvas' style="width:400px; height:500px"></div>
于 2012-09-11T10:29:45.347 回答
0

I had this too (especially in Chrome on the desktop) and solved it by resizing the map when it had finished rendering (in 'idle' state):

google.maps.event.addListenerOnce(map, 'idle', function() {
   google.maps.event.trigger(map, 'resize');
});
于 2012-10-22T11:09:06.460 回答