点击谷歌地图后获取经纬度 Get Latitude and Longitude (Location Coordinates) using Google Maps OnClick event

n this short code snippet article I will explain how to get the Geographical position coordinates of a location i.e. Latitude and Longitude when user clicks anywhere on Google Maps using the Google Maps V3 OnClick event handler.

In the below Google Map implementation, I have assigned an event handler to the Google Map within which the geographical position coordinates of a location i.e. Latitude and Longitude are captured and displayed using JavaScript alert message box.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
        window.onload = function () {
            var mapOptions = {
                center: new google.maps.LatLng(18.9300, 72.8200),
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var latlngbounds = new google.maps.LatLngBounds();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
            google.maps.event.addListener(map, 'click', function (e) {
                alert("Latitude: " + e.latLng.lat() + "rnLongitude: " + e.latLng.lng());
            });
        }
    </script>
    <div id="dvMap" style="width: 500px; height: 500px">
    </div>
</body>
</html>
点击谷歌地图后获取经纬度 Get Latitude and Longitude (Location Coordinates) using Google Maps OnClick event
点击谷歌地图后获取经纬度 Get Latitude and Longitude (Location Coordinates) using Google Maps OnClick event

 

下载:GoogleMaps_GetLocation_OnClick

原文:http://www.aspsnippets.com/Articles/Get-Latitude-and-Longitude-Location-Coordinates-using-Google-Maps-OnClick-event.aspx

 

更对参考:

Google Maps API V3: 通过邮编获取经纬度 Get Location (Latitude and Longitude) from Zip Code (Pin Code) using JavaScript

Google Maps V3: 导航到指定地址 Draw (Plot) route between User’s current location and Specified location

Google Maps V3: 通过经纬度获取地址信息 Get address from Latitude and Longitude

GMaps.js:让你快速集成 Google Maps 服务的 jQuery 插件

jQuery地图插件-jqvmap

谷歌地图查询两地开车路线 Google Maps API V3: DirectionsService (Driving Directions) example

谷歌地图添加点击事件 Google Maps API V3: Add click event listener to all (multiple) markers

Google Maps API v3: Remove Markers 移除标记

 

本文:点击谷歌地图后获取经纬度 Get Latitude and Longitude (Location Coordinates) using Google Maps OnClick event

Loading

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.