Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Enhancing Your App

Next you want to enhance your PhoneGap app to do some of the things your mobile app can do and some of the things it can't do, such as access your phone's camera.

image Note You might want to target your iPhone or iPad device when you try these as the simulator might give you errors.

Geolocation

PhoneGap uses the same objects as Mobile Safari; there's no need to change any syntax as PhoneGap just overrides these functions to call native code.

function testGeo(        {
navigator.geolocation.getCurrentPosition(geoSuccess, allError);
}

function geoSuccess(position) {
    alert('Latitude: ' + position.coords.latitude + '\n' +
              'Longitude: ' + position.coords.longitude + '\n' +
              'Altitude: ' + position.coords.altitude + '\n' +
              'Accuracy: ' + position.coords.accuracy + '\n' +
              'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
              'Heading: ' + position.coords.heading + '\n' +
              'Speed: ' + position.coords.speed + '\n' +
              'Timestamp: ' + new Date(position.timestamp) + '\n');
    }

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial