What am I doing wrong here? I want to get the latitude and longitude from a postcode with Google Maps, this is easy enough and I am getting the results but I cannot seem to save them. Here is what I am using. I just need to get and save the lng and lat, but there seems to be more than 1; I want the one in 'location'.
$get_pickup_coords = "https://maps.googleapis.com/maps/api/geocode/xml?&address=cv57bt&sensor=false";
$pickup_data = #file_get_contents($get_pick_coords);
$pickup_result = json_decode($pickup_data, true);
$latitude = $pickup_result[3];
There's a couple of errors in your script. For starters, you're using an xml output and trying to json_decode it. Corrected this by passing the json parameter in the google api instead of xml.
Secondly, $pickup_result[3] won't give you the lat longs, get it as shown below:
$get_pickup_coords = "https://maps.googleapis.com/maps/api/geocode/json?&address=cv57bt&sensor=false";
$pickup_data = file_get_contents($get_pickup_coords);
$pickup_result = json_decode($pickup_data, true);
$lat = $pickup_result['results'][0]['geometry']['location']['lat'];
$long = $pickup_result['results'][0]['geometry']['location']['lng'];
$lat and $long variables contain the latitude and longitude respectively.
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=cv57bt";
$data = json_decode( file_get_contents( $url ) );
$location=$data->results[0]->geometry->location;
echo 'Latitude:',$location->lat,' Longitude:',$location->lng;
Related
I'm accessing lat and lon via nominatim json and converting it to php array,all the stuff works until i try to acces lon into one array. If i acces to the array int its ok but if i try to get what's inside it dont.
$url = "http://nominatim.openstreetmap.org/search/".$_GET['places']."?format=json&email=gotia.ts#gmai.com";
$placeJSON = file_get_contents($url);
$arrPlace = json_decode($placeJSON);
//$lati = $arrPlace[0]; works
//That does not
$lati = $arrPlace[0]['lat'];
You Try this format
echo $lati = $arrPlace['0']->lat;
Working fine
So, I'm trying to pair Google and MapQuest's geocoding abilities because some address aren't able to be geocoded through Google, but they show up on Mapquest so I want to pair them. I was able to get the google results:
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat1 = $output->results[0]->geometry->location->lat;
$lon1 = $output->results[0]->geometry->location->lng;
How do I get the results using MapQuest? I've never used MapQuest so I have no idea how it returns the data and I haven't found anything on here or anywhere that demonstrates retrieving the data...
HELP! Thanks!
You can use Jay Sheth's sample code then get latitude and longitude:
$json = file_get_contents('http://open.mapquestapi.com/geocoding/v1/address?key={your_key_here}&location=Lancaster,PA');
$jsonArr = json_decode($json);
$lat1 = $jsonArr->results[0]->locations[0]->latLng->lat;
$lon1 = $jsonArr->results[0]->locations[0]->latLng->lng;
this code should start you off:
<?php
//Important: do not pass the callback=xyz parameter (as stated in the docs)
$json = file_get_contents('http://open.mapquestapi.com/geocoding/v1/address?key={your_key_here}&location=Lancaster,PA');
$jsonArr = json_decode($json);
print_r($jsonArr);
//Access latitude, longitude, etc. from PHP standard object
?>
More info:
http://open.mapquestapi.com/geocoding/
I have this code that gets the IP address and Latitude and Longitude of the user. However I am wanting ti display it on a map if it finds the lat and long.
$theirip = $_SERVER['REMOTE_ADDR'];
$fileinfo = file_get_contents("http://api.easyjquery.com/ips/?ip=".$theirip."&full=true");
This outputs a string like this.
{"IP":"000.000.00.000","continentCode":"Unknown","continentName":"Unknown","countryCode2":"Unknown","COUNTRY":"Unknown","countryCode3":"Unknown","countryName":"Unknown","regionName":"Unknown","cityName":"Unknown","cityLatitude":0,"cityLongitude":0,"countryLatitude":0,"countryLongitude":0,"localTimeZone":"Unknown","localTime":"0"}
I am wanting to retrieve just the cityLatitude and cityLongitude from this. I have researched some and tried some different code.
$lat = $fileinfo -> {"cityLatitude"};
but i'm not quite sure how to go about this. Any help would be appreciated!
What you have there is a JSON string, you can use json_decode to pasre it
$obj = json_decode($fileinfo);
$lat = $obj -> {"cityLatitude"};
its a JSONObject... just use the json_decode() to get data from it
no need to decode the JSON, it should work fine.
trying from here its working just fine...
try using your IP instead of $theirip = $_SERVER['REMOTE_ADDR'];
You're using PHP right? It should be
$info = json_decode($fileinfo);
$citylatitude = $info->cityLatitude;
I have looked everywhere to try and get the answer to this simple task to no avail.
I just need to get the lat/long (geotag) from an image. The docs give an example of how to update the GmlPos in the GeoRssWhere. ( http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_php.html ) But how do you just retrieve that info?
I'v tried the below, but I think i'v got something wrong.
$where = new Zend_Gdata_Geo_Extension_GeoRssWhere();
$georeff = $where->point;
can someone help?
The Picasa API returns entities as Zend_Gdata_Photos_PhotoEntry
You can use getGeoRssWhere() to get the geo data:
$geo = $photo->getGeoRssWhere();
I found a great example getting geotag to display photos on a map like I wanted to do. http://picasaphpworkshop.googlecode.com/svn-history/r11/trunk/workshop.php
The part I couldn't figure out was the $where->getPoint()->getPos(); after getting the georsshwere.
Zend_Loader::loadClass('Zend_Gdata_Media_Extension_MediaKeywords');
Zend_Loader::loadClass('Zend_Gdata_Geo_Extension_GeoRssWhere');
Zend_Loader::loadClass('Zend_Gdata_Geo_Extension_GmlPos');
Zend_Loader::loadClass('Zend_Gdata_Geo_Extension_GmlPoint');
Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoEntry');
$picasa = new Zend_Gdata_Photos();
$query = $picasa->newAlbumQuery();
$query->setUser('user#gmail.com');
$query->setAlbumName('MyAlbumNameFromURL');
$feed = $picasa->getAlbumFeed($query);
foreach($feed as $num => $photoEntry){
$where = $photoEntry->getGeoRssWhere();
$lat = $where->getPoint()->getPos();
//$lat = split(" ", $lat); // Split out the space-separated lat
}
echo "GeoReff: " . $lat . "<br />\n";
I am importing an RSS feed from the NOAA website which is returned as RSS.
The latitude and longitude values are returned as one tag which is below:
<georss:point>40.369 -73.703</georss:point>
Is it possible to 'break' apart these values and create two variables such as:
$lat = 40.369
$lng = -73.703
Here is my PHP script that is currently parsing out the XML:
$rss_title = $RSS_DOC->channel->title;
$rss_link = $RSS_DOC->channel->link;
$rss_editor = $RSS_DOC->channel->managingEditor;
$rss_copyright = $RSS_DOC->channel->copyright;
$rss_date = $RSS_DOC->channel->item->pubDate;
$rss_description = $RSS_DOC->channel->item->description;
Appreciate any resource to get me pointed in the right direction. thanks,
Yes, not too hard. Explode (edited - thanks #sdleihssirhc):
http://php.net/manual/en/function.explode.php
E.g.:
list($latt, $long) = explode(" ", $RSS_DOC->channel->item->point);
Hope it works.