java端调用百度地图api
发布网友
发布时间:2022-04-25 14:24
我来回答
共2个回答
热心网友
时间:2023-10-09 00:20
调google api吧:
<script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=false"></script>
上面引入后,
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(29.678815, 121.426489);
var myOptions = {
zoom: 12,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Hello World!"
});
var rectangle = new google.maps.Rectangle();
var rectOptions = {
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map,
clickable:false,
bounds: map.getBounds()
};
var beginlatlng = ""; //记录起始点坐标
var endlatlng = ""; //记录结束点坐标
var rectBounds = "";
var SfClick = "";
var SfMove = "";
var ClickCount = 0; //点击次数
SfClick = google.maps.event.addListener(map, 'click', function(e) {
var begin = e.latLng;
ClickCount++;
if (ClickCount == 1) {
SfMove = google.maps.event.addListener(map, "mousemove",function(e) {
beginlatlng = begin;
endlatlng = e.latLng;
rectOptions.bounds = new google.maps.LatLngBounds(beginlatlng, endlatlng);
rectOptions.map = map;
rectangle.setOptions(rectOptions);
});
} else {
google.maps.event.removeListener(SfMove);
if (window.confirm("ok")) {
ClickCount = 0;
alert('起始坐标点' + beginlatlng + '\n结束坐标点' + endlatlng)
} else {
ClickCount = 0;
rectOptions.map = null;
rectangle.setOptions(rectOptions);
}
}
});
}
</script>
热心网友
时间:2023-10-09 00:21
使用flash版本的,和java无关。
若是用JSP的话,可以将里面的坐标和名称用<%=...%>来实现,里面的数据可以用数据库里面的数据。其他诸如,图片的大小都可以自定义的。