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
Related
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;
I have the following code below, which I am trying to run to save the key in the json to a PHP varible. However, for some reason it's just not doing anything - although it seems my code is right, any ideas where I am going wrong?
<?php
$json = file_get_contents('url');
$data = json_decode($json,true);
$id = $data['s_id'];
echo($id);
?>
and the json from the external URL looks like this
[{"s_id":"20063"}]
You have an array wrapping the object
$id = $data[0]['s_id'];
i am looking for some help to find the distance between two address through php
as i can not use the google maps api. so get a way from this post
Distance between two addresses
but i need to know how can send the request using URL pattern
and grab the repose to save them in database.
http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false
thanks for any suggestion.
///////////////
After these answers i am there
$customer_address_url = urlencode($customer_address);
$merchant_address_url = urlencode($merchant_address);
$map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";
$response_xml_data = file_get_contents($map_url);
$data = simplexml_load_string($response_xml_data);
XML response is visible when i put this url : http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false
but can not printing through
echo "<pre>"; print_r($data); exit;
You can try this..
$url = "http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false";
$data = file_get_contents($url);
Now $data contains resulting xml data. You can parse this xml data using..
http://php.net/manual/simplexml.examples.php
use the haversine formula
Also check https://developers.google.com/maps/documentation/distancematrix/
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;
http://www.instamapper.com/api?action=getPositions&key=584014439054448247&num=10&format=json
is the url, which contains json data. I want to use that data and send SMS to a particular phone no if value of latitude and longitude(Extracted from JSON).
Check constraints, we can use through php. But the main problem is How to extract data from JSON file?
I don't want to give you the solution, so the below should be enough to get you started.
Read in the JSON data using file_get_contents
Parse the JSON string into a PHP object using json_decode
Your code should look something like this:
$url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247&num=10&format=json";
$contents = file_get_contents($url);
$jsonObj = json_decode($contents);
You mean something like this?
<?php
$jsonurl = "http://search.twitter.com/trends.json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
foreach ( $json_output->trends as $trend )
{
echo "{$trend->name}\n";
}