[英]<script>Not Getting Lat and Long from the given map address jquery or javascript
I want to find lat and lng from given address but i cant find same can you please help me to solve this query 我想从给定的地址中找到经纬度,但是我找不到相同的地址,你能帮我解决这个问题吗
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': "patan"}, function(results, status) {
alert(status)
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location.lat());
//$('.push-down').text("location : " + results[0].geometry.location.lat() + " " +results[0].geometry.location.lng());
} else {
$('.push-down').text("Something got wrong " + status);
}
});
</script>
Kindly try below code :- 请尝试以下代码:-
<div class="push-down"></div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> <script> var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': "patan"}, function(results, status) { //alert(status) if (status == google.maps.GeocoderStatus.OK) { var Lat = results[0].geometry.location.lat(); var Lng = results[0].geometry.location.lng(); $('.push-down').html("latitude: " + Lat + " <br/>longitude: " +Lng); } else { $('.push-down').text("Something got wrong " + status); } }); </script>
Hope it helps :) 希望能帮助到你 :)
Since your question is marked php as well, I would recommend using the Google Geocode API Web Service . 由于您的问题也被标记为php,因此建议您使用Google Geocode API Web服务 。 I find it much easier to use, than the js API. 我发现它比js API更易于使用。
Here is an example code: 这是示例代码:
<?php
// Request URL for Google Geocode API, result type = json, language = hu-HU, region = hu-HU
// Change result type, language, region to your needs
define('REQ_URL', 'https://maps.googleapis.com/maps/api/geocode/json?language=hu®ion=hu');
// Your Google API key goes here
define('API_KEY', 'your-google-api-key-goes-here');
// Address you want to geocode
// Needs to be url encoded
$address = 'address-you-want-to-geocode-goes-here';
$address = urlencode($address);
// Parsing full request url
$request_url = REQ_URL . '&address=' . $address . '&key=' . API_KEY;
// Query Google API for result
$response = file_get_contents($request_url);
$resp = json_decode($response, true);
// Result array
print '<pre>';
print_r($resp);
print '</pre>';
I hope, I could be of any help. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.