Skip to content

Instantly share code, notes, and snippets.

@terry6394
Created July 8, 2011 08:32
Show Gist options
  • Select an option

  • Save terry6394/1071371 to your computer and use it in GitHub Desktop.

Select an option

Save terry6394/1071371 to your computer and use it in GitHub Desktop.
地图
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.1&services=true"></script>
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.6.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
var location = 'Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude;
alert(location);
element.innerHTML = '<div id="container"></div>'
var map = new BMap.Map("container");
var point = new BMap.Point(position.coords.longitude, position.coords.latitude);
map.centerAndZoom(point, 15);
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
<style>
div,body,html {
margin:0;
width:320px;
height:480px;
}
</style>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment