我目前从事的项目需要我获取用户当前位置并将其保存在数据库中。稍后在 GoogleMap 中显示它
我正在使用纬度和经度保存用户位置。 我可以使用此数据创建一个重定向到 map 的链接,但我无法使用它生成 iframe 链接。
例如: LAT: 13.033419 LNG: 77.563976
以这种方式建立链接(可以在 btn 上使用):
http://maps.google.com/?q=13.033419,77.563976
希望使用这个 LAT 和 LNG 数据生成这个:
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3887.035379846286!2d77.56178731437602!3d13.03341899081541!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zMTPCsDAyJzAwLjMiTiA3N8KwMzMnNTAuMyJF!5e0!3m2!1sen!2sin!4v1483076445133" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
准确地说是: pb=!1m18!1m12!1m3!1d3887.035379846286!2d77.56178731437602!3d13.03341899081541!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.12!%3m3!1m3!1 2zMTPCsDAyJzAwLjMiTiA3N8KwMzMnNTAuMyJF!5e0!3m2!1sen!2sin!4v1483076445133
请告诉我是否有办法实现这一目标。
如果有的话,即使是另一种方法也很受欢迎:)
最佳答案
我认为这应该可以解决您的问题
<!DOCTYPE html>
<html>
<head>
<script data-require="angularjs@1.5.7" data-semver="1.5.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="googleControllerTest">
<iframe ng-src="{{url}}" width="600" height="450" frameborder="0" style="border:0" allowfullscreen=""></iframe>
</div>
<h1>Hello Plunker!</h1>
</body>
</html>
--- Code
angular.module('app', [
]).controller('googleControllerTest', function($scope, $sce, $interpolate){
$scope.data = {
lat: 13.033419,
long: 77.563976
}
$scope.value = $interpolate("https://maps.google.com/maps?q={{lat}},{{long}}&hl=es;z=14&output=embed")($scope.data);
$scope.url = $sce.trustAsResourceUrl($scope.value)
})
关于javascript - 将纬度、经度转换为 iframe 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41391302/