У меня есть карта, у меня есть функция geocodeLatLng()
, которая вызывается внутри функции getPosition()
, но, к сожалению, geocodeLatLng()
или координаты, преобразованные в название места и помещающие его в карту, не работают.В getPosition()
я могу получить currentlatlng
, моя проблема в том, как поместить его в id=address
, который является входом из таблицы.
Я пытался document.getElementById("address").innerHTML=currentlatlng;
, но это не сработало.
<script>
function getPosition() {
navigator.geolocation.getCurrentPosition(position => {
currentLatLon = [position.coords.latitude, position.coords.longitude];
infowindow = new google.maps.InfoWindow();
map = new google.maps.Map(
document.getElementById('map'), {
center: new google.maps.LatLng(...currentLatLon),
zoom: 20
});
var geocoder = new google.maps.Geocoder();
service = new google.maps.places.PlacesService(map);
document.getElementById("curr").innerHTML=currentLatLon;
document.getElementById("address").innerHTML=currentLatLon;
});
}
</script>
<form name="frm_map" id="frm_map">
<table>
<tbody><tr>
<th>Address</th>
<td>
<input type="text" name="address" id="address" placeholder="Enter a location" autocomplete="off">
</td>
</tr>
<tr>
<th>Radius</th>
<td>
<input type="text" name="radius" id="radius" value="1000" placeholder="In KM">
</td>
</tr>
<tr>
<th>Types</th>
<td>
<div id="type_holder" style="height: 200px; overflow-y: scroll;"><div><label><input type="checkbox" class="types" value="amusement_park">Amusement park</label></div><div><label><input type="checkbox" class="types" value="aquarium">Aquarium</label></div><div><label><input type="checkbox" class="types" value="bus_station">Bus station</label></div><div><label><input type="checkbox" class="types" value="cafe">Cafe</label></div><div><label><input type="checkbox" class="types" value="campground">Campground</label></div><div><label><input type="checkbox" class="types" value="convenience_store">Convenience store</label></div><div><label><input type="checkbox" class="types" value="department_store">Department store</label></div><div><label><input type="checkbox" class="types" value="home_goods_store">Home goods store</label><div><label><input type="checkbox" class="types" value="meal_takeaway">Meal takeaway</label></div><div><label><input type="checkbox" class="types" value="park">Park</label></div><div><label><input type="checkbox" class="types" value="parking">Parking</label></div><div><label><input type="checkbox" class="types" value="pet_store">Pet store</label></div><div><label><input type="checkbox" class="types" value="police">Police</label></div><div><label><input type="checkbox" class="types" value="restaurant">Restaurant</label></div><div><label><input type="checkbox" class="types" value="rv_park">Rv park</label></div><div><label><input type="checkbox" class="types" value="store">Store</label></div><div><label><input type="checkbox" class="types" value="taxi_stand">Taxi stand</label></div><div><label><input type="checkbox" class="types" value="train_station">Train station</label></div><div><label><input type="checkbox" class="types" value="veterinary_care">Veterinary care</label></div><div><label><input type="checkbox" class="types" value="zoo">Zoo</label></div></div></div>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" value="Show" id="submit" onclick="renderMap();">
<input type="reset" value="Reset">
</td>
</tr>
<tr>
<td>
<div class="ss"><a href="index1.php" style="font-size:18px; font-weight: bold; color: #666; text-decoration:none; padding-top:1000px;">HOME</a></div>
</td>
</tr>
</tbody></table>
</form>