In this section, we add the ability to tag a speaker with his/her location information. In this sample application, we display the raw information (longitude/latitude) in an alert. In a real-life application, we would typically save the location in the database as part of the speaker information and show it on a map.
The code below works when running the application as a PhoneGap app on your device. It should also work in Chrome on the desktop when the page is served with the http:// protocol, and in Firefox, regardless of the protocol (http:// or file://).
phonegap plugin add org.apache.cordova.geolocation
<li class="table-view-cell media">
<a hre="#" class="push-right add-location-btn">
<span class="media-object pull-left"></span>
<div class="media-body">
Add location
</div>
</a>
</li>
this.$el.on('click', '.add-location-btn', this.addLocation);
Make sure you add this line as the last line of the initialize() function (after this.$el is assigned).
this.addLocation = function(event) {
event.preventDefault();
navigator.geolocation.getCurrentPosition(
function(position) {
alert(position.coords.latitude + ',' + position.coords.longitude);
},
function() {
alert('Error getting location');
});
return false;
};