how to set a polyline on google maps every time when i click twice(make two markers) on maps,
Posted
by zjm1126
on Stack Overflow
See other posts from Stack Overflow
or by zjm1126
Published on 2010-03-12T14:32:21Z
Indexed on
2010/03/12
14:37 UTC
Read the original article
Hit count: 237
this is my code :
thanks
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=5.0,user-scalable=yes">
</head>
<body onload="initialize()" onunload="GUnload()">
<style type="text/css">
</style>
<div id="map_canvas" style="width: 500px; height: 300px;float:left;"></div>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script src="jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA-7cuV3vqp7w6zUNiN_F4uBRi_j0U6kJrkFvY4-OX2XYmEAa76BSNz0ifabgugotzJgrxyodPDmheRA&sensor=false"type="text/javascript"></script>
<script type="text/javascript">
//**********
function initialize() {
if (GBrowserIsCompatible()){
//var map = new GMap2(document.getElementById("map_canvas"));
//map.setCenter(new GLatLng(39.9493, 116.3975), 13);
var map = new GMap2(document.getElementById("map_canvas"));
var center=new GLatLng(39.917,116.397);
map.setCenter(center, 13);
map.addOverlay(new GMarker(new GLatLng(39.917,116.397)));
map.enableDrawing()
//GEvent.addListener(map, "mouseover", function() {
//alert("???????");
//});
var one;
aFn=function(y_scale,x_scale){
//************
//function p(){
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var point = new GLatLng(southWest.lat() + latSpan * (1-y_scale),
southWest.lng() + lngSpan * x_scale);
if(!one){
map.addOverlay(new GMarker(point));
one=point;
}else{
var polyline = new GPolyline([one,point], "#ff0000", 5);
map.addOverlay(polyline);
one=0;
}
}
//**********
//*************
}
}
</script>
</body>
</html>
© Stack Overflow or respective owner