How to get GPS coordinates from blackberry when logging into a website
Im trying to do a website where a user will log into the website with a username and password with his blackberry example 9800 tourch. Then i want the web page to use the Bl开发者_运维技巧ackberry's GPS to get the coordinates. Can someone please help me with some kind of code.
Thank you in advance. M
You can try these methods.
Using HTML5 Geolocation in your Web or BlackBerry WebWorks applications
javascript geo location framework for the mobile web
I tried both of those links and both return 0,0 for the latitude and longitude on my blackberry curve (9330, OS 6.0). This is very disappointing because I've been using #2 above for every other device. After digging around for a nearly a day I found this to work on my blackberry (although I can't get the removeLocation handler to work.
<html>
<body>
<script language="Javascript">
function removeLocation() {
// dummy function since removeLocationUpdate requires a callback
window.alert("location handler removed");
}
function getLocation() {
window.alert("Your new position is " + blackberry.location.latitude + " degrees latitude and " + blackberry.location.longitude + " degrees longitude.");
blackberry.location.removeLocationUpdate(removeLocation);
}
if(blackberry.location.GPSSupported) {
blackberry.location.setAidMode(1);
blackberry.location.refreshLocation();
blackberry.location.onLocationUpdate(getLocation);
} else {
alert('nope');
}
</script>
<p>detecting location....</p>
</body>
</html>
This script was found using help from the last post on this link: http://www.blackberryforums.com/general-legacy-device-discussion/23544-7130e-gps-location-based-services-2.html
You could try something like this:
Note* replace: YOUR_DESTINATION_ADDRESS with an address in a format like: "147+Wyndham+Street+N+,+Suite+206,+Guelph,+On,+N1H+4E9"
<div id="Map" style="width: 100%; height: 600px;"> </div>
<script type="text/javascript">
$(function(){
var zoom = 11;
function success(position) {
var LAT = position.coords.latitude;
var LONG = position.coords.longitude;
$('#Map').append('<p>Current Latitude: ' + LAT + '<br/>Current Logitude: ' + LONG +'<br/><br/>Note* This may not display your exact location, but just your city. Works better on mobile devices</p>');
var map = '<iframe style="width: 100%; height: 600px;" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ca/maps?source=s_d&saddr=' + LAT +',+' + LONG +'&daddr=**YOUR_DESTINATION_ADDRESS**&ie=UTF8&t=hz=' + zoom + '&output=embed"></iframe>';
$('#Map').append(map);
}
function error(){
/*Error Code*/
}
function MakeMap(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
}
MakeMap();
});
</script>
精彩评论