您的位置:首页 > 运维架构

Google Maps Application Developing —— Location

2012-01-30 00:37 381 查看
// (function () {
var map;
window.onload = function () {
// Creating a map
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(39.9, 116.4),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
// Checking if geo positioning is available
if (geo_position_js.init()) {
// Creating a settings object
var settings = {
enableHighAccuracy: true
};
// Trying to determine the location of the user
geo_position_js.getCurrentPosition(setPosition, handleError, settings);
} else {
alert('目前设备不支持地理定位!');
}
};
function handleError(error) {
alert('Error = ' + error.message);
}
function setPosition(position) {
// Creating a LatLng from the position info
var latLng = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
map.setCenter(latLng);
// Adding a marker to the map
var marker = new google.maps.Marker({
position: latLng,
map: map
});
// Creating an InfoWindow
var infoWindow = new google.maps.InfoWindow({
content: '你在这里!'
});
// Adding the InfoWindow to the map

infoWindow.open(map, marker);
// Zooming in on the map
map.setZoom(15);
}
})();
// ]]>

<script type="text/javascript">
(function () {
var map;
window.onload = function () {
// Creating a map
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(31.35, 3.51),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
// Checking if geo positioning is available
if (geo_position_js.init()) {
// Creating a settings object
var settings = {
enableHighAccuracy: true
};
// Trying to determine the location of the user
geo_position_js.getCurrentPosition(setPosition, handleError, settings);
} else {
alert('目前设备不支持地理定位!');
}
};
function handleError(error) {
alert('Error = ' + error.message);
}
function setPosition(position) {
// Creating a LatLng from the position info
var latLng = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
// Adding a marker to the map
var marker = new google.maps.Marker({
position: latLng,
map: map
});
// Creating an InfoWindow
var infoWindow = new google.maps.InfoWindow({
content: '你在这里!'
});
// Adding the InfoWindow to the map

infoWindow.open(map, marker);
// Zooming in on the map
map.setZoom(15);
}
})();
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: