Lat, Uzun koordinatları kullanarak en yakın yeri almak için Google Map API ve PHP ile Geocoding Ters

1 Cevap php

Ben google map API coğrafi kodlama ve php ters kullanılarak (uzun lat) koordinatları bir yakın adres veya şehri almak için bir işlev gerekir ... bazı örnek kod verin

1 Cevap

Sen Google Maps API olarak GClientGeocoder nesne üzerinde getLocations yöntemi kullanmak gerekir

var point = new GLatLng (43,-75);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) {
    // access the address from the placemarks object
    alert (result.address);
    });

Bir working example of this here bulabilirsiniz. Bu örnek aynı zamanda iki nokta arasındaki yürüme yön yapıyor, ancak bunu GEOCODE her zaman yapar dragend dinleyici getLocations çağrı bir göz varsa, bitiş noktası taşınır.

EDIT: Tamam. Bu madde, sunucu tarafında yapıyoruz. Bu HTTP Geocoding service kullanmanız gerekir demektir. Bunu yapmak için, bağlantılı makalede açıklanan URL biçimini kullanarak bir HTTP isteği yapmak gerekir. Sen HTTP yanıtı ayrıştırmak ve adresini çekin:

// set your API key here
$api_key = "";
// format this string with the appropriate latitude longitude
$url = 'http://maps.google.com/maps/geo?q=40.714224,-73.961452&output=json&sensor=true_or_false&key=' . $api_key;
// make the HTTP request
$data = @file_get_contents($url);
// parse the json response
$jsondata = json_decode($data,true);
// if we get a placemark array and the status was good, get the addres
if(is_array($jsondata )&& $jsondata ['Status']['code']==200)
{
      $addr = $jsondata ['Placemark'][0]['address'];
}

N.B. Google Maps terms of service açıkça bir Google Haritada sonuçları koymadan coğrafi kodlama veri yasak olduğunu belirtiyor.