- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 google maps v3 和 php 的应用程序。我需要向谷歌地图动态添加方向路线,并使用 php 将它们插入数据库。工作示例是 http://pastehtml.com/view/blzvshf3l.html代码是这样的:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Add Route</title>
<style>
html, body {
margin: 0;
padding: 0;
}
#map_canvas {
height: 600px;
margin-bottom:20px;
}
@media print {
html, body {
height: auto;
}
#map_canvas {
height: 650px;
}
}
#controls{
margin-bottom:20px;
}
#debug{
height:200px;
overflow:auto;
margin-bottom:20px;
}
#description{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var markers = [];
var directions = [];
function initialize() {
var bm = new google.maps.LatLng(47.65668913620708, 23.56867790222168);
var myOptions = {
zoom: 16,
center: bm,
minZoom: 13,
maxZoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
google.maps.event.addListener(map, 'click', addRoute);
}
function addRoute(event) {
if(markers.length < 2){
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
}
if(markers.length == 2){
var start = markers[0].getPosition();
var end = markers[1].getPosition();
putDirections(start, end);
$(markers).each(function(i, marker){
google.maps.event.addListener(marker, 'dragend', function(){
clearDirections();
var start = markers[0].getPosition();
var end = markers[1].getPosition();
putDirections(start, end);
});
});
}
}
function putDirections(start, end){
var direction = [];
var polylineOptions = {
map: map,
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 5
}
direction['directionsDisplay'] = new google.maps.DirectionsRenderer({
polylineOptions: polylineOptions,
suppressInfoWindows: true
});
direction['directionsDisplay'].suppressMarkers = true;
direction['directionsDisplay'].preserveViewport = true;
direction['directionsDisplay'].draggable = true;
direction['directionsService'] = new google.maps.DirectionsService();
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.WALKING //DRIVING, WALKING, BICYCLING
};
direction['directionsDisplay'].setMap(map);
direction['directionsService'].route(request, function(response, status){
if(status == google.maps.DirectionsStatus.OK){
direction['directionsDisplay'].setDirections(response);
}
});
directions.push(direction);
}
function clearMarkers(){
$(markers).each(function(i, marker){
marker.setMap(null);
});
markers = [];
}
function clearDirections(){
$(directions).each(function(i, direction){
direction['directionsDisplay'].setMap(null);
});
directions = [];
}
function clearDebug(){
$('#debug').html('');
}
function debug(){
clearDebug();
var debug = '';
$(markers).each(function(i, marker){
debug += '<b>Marker #'+(i+1)+'</b> position: latitude=<b>'+marker.getPosition().lat()+'</b>, longitude=<b>'+marker.getPosition().lng()+'</b><br>';
});
if(markers.length == 0){
debug += 'Add some markers first!';
}
$('#debug').html(debug);
}
$(document).ready(function(){
initialize();
});
</script>
</head>
<body>
<div id="map_canvas"></div>
<div id="controls">
<input type="button" value="Reset Directions and Markers" onclick="clearMarkers();clearDirections();clearDebug();">
<input type="button" value="Get Markers Location" onclick="debug();">
</div>
<div id="description">
<strong>Description:</strong><br>
Markers and routes can be dragged to create a new directions. They can also be deleted.
</div>
<div id="debug"></div>
</body>
</html>
我需要能够更改(拖动)路线(示例就是这样做的)。问题是:如何获取 2 点(标记)之间所有路线的所有坐标(纬度、经度)?我需要将方向从数据库绘制回 map 。
我能够得到两点之间的第一组坐标,如下所示:
directions[0]['directionsDisplay'].getDirections().routes[0].overview_path
这是一个坐标数组。这是获取坐标的正确方法吗?拖动路线时的事件名称是什么?
最佳答案
overview_path
只会让您概览(即简化的行)。如果这适合您的用例,请务必使用它。否则,请继续阅读。
DirectionsRoute
对象有一个 legs
属性。这是 DirectionsLeg
的数组对象,它又具有 steps
的属性。每个DirectionsStep
有一个路径
。
如果您收集所有腿
的所有步骤
的所有路径
,您将能够构建详细的路径对于整个路线。
此外,执行此操作后,如果您想减小发回 PHP 服务器的大小,请使用 encoding
压缩路径的库。
考虑使用 Directions API ,可作为 PHP 的 Web 服务访问。特别是,您可能希望从用户定义的路径(拖动)中获取航路点并将它们发送到您的服务器,以便它可以运行适当的 Directions API
当用户完成拖动路径时触发的事件称为 directions_changed
。请参阅 DirectionsRenderer
的引用资料.
关于google-maps - 我如何从头到尾获取谷歌地图v3方向坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014830/
这两个包看起来非常相似: http://www.passportjs.org/packages/passport-google-oauth2/ http://www.passportjs.org/pa
我想在我的网站上添加通过 Google 和 Twitter 登录的按钮。我需要只使用应用程序的客户端而不是服务器端来完成此操作。但我没有找到任何 API。对于我发现的所有内容,我需要使用带有 key
我使用此链接通过 google plus 共享我的页面。 https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fcompany%2
我正在尝试学习 google API,并且我的经验是使用 Python,因此我尝试使用 google api python 客户端来访问一些 google 服务,但在构建服务对象时遇到错误。 从 ap
在其实际的实时托管平台上构建实时站点的努力中,有没有办法告诉谷歌不要索引该网站?我发现了以下内容: http://support.google.com/webmasters/bin/answer.py
我正在开发一个 iOS 应用程序。当我运行用于 google+ 登录的程序时,在我点击允许访问按钮后,会显示此消息。 You've reached this page because we have
我有一个非常复杂的网站,每个页面包含 11 个 js 文件。 我最近添加了 google +1 按钮,代码如下: 这会正确显示 +1 按钮,直到我单击它。当我单击它时,出现此错误:https://
我正在尝试使用 google API 创建一个 html 文件,以便在 google MAPS 上显示 KML 文件。 这是 HTML 代码: function initMap() {
我是使用 Google Benchmark 的新手,在本地运行代码与在 Quick-Bench.com 上运行代码时,我收到了运行相同基准测试(下方)的不同结果,该基准测试使用 C++ 检索本地时间.
我已按照 Google 网站上的说明通过添加以下元标记在我的 AngularJS 网站上启用 Ajax 抓取: 呈现的内容有一些链接,如: User 1 User 2 User 3 还有一些呈现动态
通过 Google 手册实现 Google AppInvite - link . 启动 Invite Activity 并在 LogCat 中获取下一步: E/AppInviteAgent: Get
那么有人用过 Google 的 Go 吗?我想知道数学性能(例如触发器)与其他具有垃圾收集器的语言(如 Java 或 .NET)相比如何? 有人调查过吗? 最佳答案 理论性能:纯 Go 程序的理论性能
Stackdriver 测试我的网站启动速度慢 我们使用 cloudflare 作为我们的站点 CDN 提供商。我们使用 stackdriver 从外部测试站点可用性,我们将时间检查间隔设置为 1 分
我正在尝试使用 stax.GeneralConv() ( https://jax.readthedocs.io/en/latest/_modules/jax/experimental/stax.htm
我有一个从谷歌金融中提取日内数据的软件。但是,由于昨天 Google 更新了 API,所以软件报错了 Conversion from string HTML HEAD meta http-equiv=
我们在尝试从 Google 获取 oAuth token 时遇到“redirect_uri_mismatch”错误: [client 127.0.0.1:49892] {\n "error" : "
我的网站正在使用 Google reCAPTCHA 控件,但我听说它被阻止了 中国,反正我看到有人报告说将 API 更改为 https://www.recaptcha.net在中国工作? Anyone
背景 WordPress Google Adsense 谷歌自动插入 anchor 定广告 https://pptmon.com 问题 如下图所示,主播广告的容器高度太大了! 如何调整高度? 这是谷歌
我在使用 Google Colab 时遇到问题。当我想制作一个新的 Python3 Notebook 时,由于我登录了我的 Google 帐户,因此无法加载刚刚打开的新页面。 我该怎么办? 感谢您的帮
我正在使用 facebook和 google oauth2使用 passport js 登录, 有了这个流 用户点击登录按钮 重定向到 facebook/google auth 页面(取决于用户选择的
我是一名优秀的程序员,十分优秀!