简体   繁体   English

<script>Not Getting Lat and Long from the given map address jquery or javascript

[英]<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&region=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.

相关问题 获取在 leaflet map 上使用 mapbox 搜索的地址的纬度/经度 - Getting the lat/long of the address searched with mapbox on the leaflet map 在Javascript中从经纬度获取城市名称 - Getting the cityname from lat/long in Javascript 从地图上的数据库和绘制标记中获取gps纬度,经度值? - Getting gps Lat, Long values from DataBase and Draw marker on map? 在谷歌地图上无法通过纬度和经度获得地址 - not geting address with help of lat and long in google map 从自动完成地址输入中获取经纬度,并使用Google Maps API在下面显示地图 - Get Lat and Long from autocomplete address input and show the map below with google maps API 从 angular 中的给定 lat 和 long 列表中检测边界 lat long - detect boundary lat longs from given list of lat and long in angular 我如何通过给定的纬度/经度获取地址 - How do i get address by given lat/long 使用JQuery或Javascript选择谷歌地图的下拉更改 - on selecting the drop down change lat long of Google Map using JQuery or Javascript 如何用lat格式的经纬度反向解析google map地址? - how to reverse paring google map address with lat,long in json format? 如何在Google Map API中使用地址代替纬度/经度 - How to use Address instead of Lat/Long in Google Map API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM