Yêu cầu thg 9 27, 2019 7:49 SA 504 0 4
  • 504 0 4
0

Lấy thông tin địa lý khi có kinh độ , vĩ độ latitude ,longitude

Chia sẻ
  • 504 0 4

Hello các bro, em có một câu hỏi là muốn lấy ra thông tin về vị trí địa lý khi có kinh độ và vĩ độ ~.~ mong các bro giúp đỡ

4 CÂU TRẢ LỜI


Đã trả lời thg 9 27, 2019 7:55 SA
+1

bạn sử dụng google map API nhé: Hồi trước mình code cái này thì là 1 điểm trên google map API đã có thông tin info đó rồi. Đây là hàm mình viết

function showInfo(marker) {
			google.maps.event.addListener(marker, 'click', function(event) {
				var geocoder = new google.maps.Geocoder;
				var infowindow = new google.maps.InfoWindow;
				geocoder.geocode({
					'location': event.latLng
				}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						if (results && results.length > 0) {
							marker.formatted_address = results[0].formatted_address;
							//updateMarkerAddress(results[0].formatted_address);
						} else {
							marker.formatted_address = 'Cannot determine address at this location.';
							//updateMarkerAddress('Cannot determine address at this location.');
						}
						infowindow.setContent(marker.formatted_address + "<br>coordinates: " + marker.getPosition().toUrlValue(6));

					} else {
						alert('Geocode was not successful for the following reason: ' + status);
					}

				});
				//infowindow.setContent("double click to delete this waypoint");
				infowindow.open(map, this);
				//updateMarkerPosition(event.latLng);
				google.maps.event.addListener(marker, "dragstart", function() {
					infowindow.close();
				});
			});
		}
Chia sẻ
Avatar Nguyễn Tuấn Vũ @NguyenTuanVu2105
thg 9 27, 2019 8:41 SA
Đã trả lời thg 9 27, 2019 7:51 SA
0
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var geocoder = new google.maps.Geocoder();
var address = "new york";

geocoder.geocode( { 'address': address}, function(results, status) {

if (status == google.maps.GeocoderStatus.OK) {
    var latitude = results[0].geometry.location.lat();
    var longitude = results[0].geometry.location.lng();
    alert(latitude);
    alert(longitude);
    } 
}); 
</script>

Trích: stackoverflow

Chia sẻ
Avatar Tran Dai Son @tran.dai.son
thg 9 30, 2019 9:40 SA

References: https://developer.mozilla.org/vi/docs/Web/API/Geolocation_API

if ("geolocation" in navigator) {
  / * định vị địa lý có sẵn * /
  navigator.geolocation.getCurrentPosition(function(position) {
    console.log('latitude', location.coords.latitude, 'longitude', location.coords.longitude);
  });
} else {
  / * định vị địa lý KHÔNG có sẵn * /
  alert('Geolocation unsupported!');
}


// ES6 syntax
if ("geolocation" in navigator) {
  navigator.geolocation
    .getCurrentPosition(({ coords: { latitude, longitude } }) => console.log('latitude', latitude, 'longitude', longitude));
} else {
  / * định vị địa lý KHÔNG có sẵn * /
  alert('Geolocation unsupported!');
}
Avatar Xuân Dương @xuanduong1998
thg 11 6, 2019 8:33 SA

em cảm ơn

Đã trả lời thg 9 27, 2019 8:43 SA
0
<script type="text/javascript">
var map;
function initMap() {
var mapCenter = new google.maps.LatLng(47.6145, -122.3418); //Google map Coordinates
map = new google.maps.Map($("#map")[0], {
   	center: mapCenter,
   	zoom: 8
     });
}

$("#find_btn").click(function (){
   if ("geolocation" in navigator){
   		navigator.geolocation.getCurrentPosition(function(position){ 
   				infoWindow = new google.maps.InfoWindow({map: map});
   				var pos = {lat: position.coords.latitude, lng: position.coords.longitude};
   				infoWindow.setPosition(pos);
   				infoWindow.setContent("Found your location <br />Lat : "+position.coords.latitude+" </br>Lang :"+ position.coords.longitude);
   				map.panTo(pos);
   			});
   	}else{
   		console.log("Browser doesn't support geolocation!");
   }
});
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>

Nguồn: https://www.sanwebe.com/2016/04/get-current-location-of-user-using-jquery

Chia sẻ
Đã trả lời thg 11 5, 2019 5:29 SA
0

Mình có viết 1 bài, bạn có thể xem tại đây nhé https://viblo.asia/p/location-trong-android-vyDZOp8klwj

Chia sẻ
Avatar Xuân Dương @xuanduong1998
thg 11 6, 2019 8:33 SA

dạ em cảm ơn

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí