Skip to content

Instantly share code, notes, and snippets.

@zxkane
Created December 22, 2013 10:39
Show Gist options
  • Save zxkane/8080722 to your computer and use it in GitHub Desktop.
Save zxkane/8080722 to your computer and use it in GitHub Desktop.
convert points of Google map to Baidu map
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,300,700" />
<link rel="stylesheet" href="http://cdnjscn.b0.upaiyun.com/libs/foundation/5.0.2/css/normalize.min.css">
<link rel="stylesheet" href="http://cdnjscn.b0.upaiyun.com/libs/foundation/5.0.2/css/foundation.min.css">
<script src="http://cdnjscn.b0.upaiyun.com/libs/foundation/5.0.2/js/vendor/jquery.min.js"></script>
<script type="text/javascript"
src="http://api.map.baidu.com/api?v=2.0&ak=5aaddbae69513573cd7f693bbdcbe12a"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/changeMore.js"></script>
</head>
<body>
<section role="main">
<div class="row">
<h2>Google地图坐标</h2>
<textarea id="google_points" rows="40" cols="0" style="height: 300px">
</textarea>
<a class="button radius">转换</a>
<h2>转换结果</h2>
<p id="result"></p>
<p id="error"></p>
</div>
</section>
<script src="http://cdnjscn.b0.upaiyun.com/libs/foundation/5.0.2/js/foundation/foundation.min.js"></script>
<script src="http://cdnjscn.b0.upaiyun.com/libs/foundation/5.0.2/js/vendor/custom.modernizr.min.js"></script>
<script>
$(document).foundation();
var points = [];
var line = 1;
var callback = function(xyResults) {
var convertedPoints = [];
var xyResult = null;
var text = "";
var error = "";
for ( var index in xyResults) {
xyResult = xyResults[index];
if (xyResult.error != 0) {
error += points[index].lat + "," + points[index].lng + "=> error happened!";
continue; //TODO better error handling
}
line++;
var point = new BMap.Point(xyResult.x, xyResult.y);
text += points[index].lat + "," + points[index].lng + "=>" + point.lat + "," + point.lng + "<br/>";
}
$("#result").append(text);
$("#error").append(error);
};
$(".button").click(function() {
data = eval($("#google_points").val());
for ( var idx in data) {
point = data[idx];
var point = new BMap.Point(point.lng, point.lat);
points.push(point);
/* if (points.length == 20) {
BMap.Convertor.transMore(points, 2, callback);
points = [];
} */
}
if (points.length > 0) {
BMap.Convertor.transMore(points, 2, callback);
}
$("#result").append("总计" + line + "个地点转换.");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment