- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从 Firebase 数据库中检索纬度和经度。这些值存储在变量中,即纬度和经度。但是,当我尝试使用这些值在 map 上设置标记时,它不起作用,但是当我给出静态纬度和位置时,标记就会出现。请帮帮我。谢谢
这是我用来检索位置并将其显示在 map 上的 html 文件的代码。`
<head>
<title>Data From Firebase Database</title>
<!--<meta http-equiv="refresh" content="5" > -->
<style>
#map{
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<div class= ""mainDiv" align= "left">
<h1> Locations </h1>
<table>
<thead>
<tr>
<td>Latitude</td>
<td>Longitude</td>
</tr>
</thead>
<tbody id="table_body">
</tbody>
</table>
</div>
<script src= "https://www.gstatic.com/firebasejs/3.3.2/firebase.js"></script>
<script>
var config = {
apiKey: "AIzaSyCU7LWliFjX7iWtNkZHhuZI0jvih6rffFI",
authDomain: "test26sep-eae46.firebaseio.com",
databaseURL: "https://test26sep-eae46.firebaseio.com/",
storageBucket: "test26sep-eae46.appspot.com",
};
firebase.initializeApp(config);
</script>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script>
var rootRef = firebase.database().ref();
rootRef.on("child_added", snap =>{
var latitude = snap.child("latitude").val();
var longitude = snap.child("longitude").val();
initMap(latitude,longitude);
$("#table_body").append("<tr><td>" + latitude + "</td><td>" + longitude + "</td></tr>");
});
</script>
<h1>Map</h1>
<div id="map"></div>
<script>
function initMap(latitude,longitude){
//alert('Values have been gathered click ok to show map !! Welcome Taj , from Arslan !! :PP');
var options = {
zoom: 8,
center: {lat: 31.5546,lng:74.3572}
}
var map = new google.maps.Map(document.getElementById('map'), options);
//show an alert to check if the values are being fetched from firebase database stored in latitude and longitude.
alert (latitude + " " + longitude);
var marker = new google.maps.Marker({
position:{lat: latitude, lng: longitude},
map:map,
});
var infoWindow = new google.maps.InfoWindow({
content:'<h4>Lahore</h4>'
});
marker.addListener('click', function(){
infoWindow.open(map, marker);
});
}
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD0w2dY7OZvF6nBvnLLxzAzXi05l_8jc-o">
</script>
</body>
</html>
`
最佳答案
那么你在哪里:
var latitude = snap.child("latitude").val();
var longitude = snap.child("longitude").val();
这些值从 .val()
作为字符串返回。您必须将它们转换为数字才能与 Google map 配合使用。
就这样做:
initMap(parseFloat(latitude), parseFloat(longitude));
或者,您将它们与 Maps API 一起使用,例如
position:{lat: parseFloat(latitude), lng: parseFloat(longitude)}
关于javascript - 如何在 htlm 和 java 脚本中使用从 firebase 数据库检索的纬度和经度在 map 上显示标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46522498/
我正在开发一个应用程序,用户可以在其中搜索其位置附近的项目。 当用户注册我的服务时,会获取他们的经/纬度坐标(这实际上是从邮政编码中获取的,然后通过 Google 查找经度/纬度坐标)。当用户添加一个
所以:我有以下函数,改编自在线找到的公式,它采用两个纬度/经度坐标并计算它们之间的距离(以英里为单位)(沿着球形地球): public static double distance (double l
我有一个给定点(经度、纬度),我想获取给定点 5 英里半径范围内的所有点范围? 最佳答案 我只是在这里猜测,但我认为您需要找到一种不同的方法。如果您尝试使用 Foursquare、Google map
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我找到了一些代码,用于将纬度/经度转换为给定图像上的像素,反之亦然。我将其移植到 JavaScript,但在纬度上得到了不正确的返回值。我测试了原始的、未修改的代码,它给出了同样的不准确之处。下面是带
我用了AstroPy EarthLocation 获取传播卫星轨道的纬度、经度和高度 loc = coord.EarthLocation(*itrs.cartesian.xyz)。现在,我尝试使用 n
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: how to do location based search Getting similar longit
我有一个超过 15000 个经纬度坐标的列表。给定任何 X、Y 坐标,在列表中找到最近坐标的最快方法是什么? 最佳答案 您将需要使用名为 Voronoi diagram 的几何结构。 .这将平面划分为
For people interested in this topic: the accepted answer involves some concepts that I think are wel
我的应用程序上有一张 map ,它显示 2 种注释:位置和位置集群。当我放大集群时,集群会展开以显示集群中包含的位置。当这些位置添加到 map 时,其父簇的坐标将存储在注释对象中。我想要做的是制作一个
关于纬度/经度计算的简单问题。 我想获取一个值集,例如Lat: 55.123456 Long -6.123456 并计算出任意距离的四个点。 作为给定的正方形,我想计算出左侧和右侧的纬度值。因此红线距
Postgis中Linestring中的点(由osm2pgsql从osm导入)按顺序描述(经度,纬度) 例如慕尼黑 map 中的线串 'LINESTRING(11.4068032 47.8580927
给定左上长/纬度和右下长/纬度,我如何确定给定的长/纬度是否落在矩形内? 理想情况下我会看类似的东西 bool IsWithinArea(float topLeftLat,float topLeftL
几天来,我一直在尝试让纬度/经度检查器、速度计、高度计工作,但似乎没有任何工作。我尝试过使用 Android 的内置 locationmanager 和 google play 服务。现在我回来尝试
我有经纬度形式的位置坐标,例如:23⁰ 39' 24.8"N & 58⁰ 11' 36.5"E,请参见下图。但是在我的工作场所我使用 ArcGIS 并且它似乎不支持度数(纬度,经度)形式的坐标。我现在
网上看了一些教程,发现LocationManager就是这样做的。这是我在网上找到的代码。但是,我不明白。为什么我不能得到长/纬度?为什么要经历所有“改变”位置的事情...... lm=(Locati
我一直在关注此网站的教程:' http://wptrafficanalyzer.in/blog/storing-google-maps-android-api-v2-marker-locations-
我需要使用用户当前的纬度/经度和数据库中存储的一些值进行一些计算。问题是 Location.getLatitude() 返回一个类似 4119778.0 的值,而我在数据库中的值保存为 41.1675
所以在 PostgreSQL 中,我有一堆 long/lat 的几何值,其格式如下: 0101000020E610000095B9F94674CF37C09CBF0985083B5040 所以在 Po
在 GoogleMap 中,有标记的纬度和经度概念。 MySQL 中的 Point 数据类型有两个坐标 x 和 y。我不知道 Point 的坐标代表什么;所以我想知道什么表示 Point 根据 Goo
我是一名优秀的程序员,十分优秀!