get lat long from address php

Solutions on MaxInterview for get lat long from address php by the best coders in the world

showing results for - "get lat long from address php"
María
11 Jun 2017
1<?php
2$address = "Kathmandu, Nepal";
3$url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&key=apikey';
4
5$ch = curl_init();
6curl_setopt($ch, CURLOPT_URL, $url);
7curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
8$responseJson = curl_exec($ch);
9curl_close($ch);
10
11$response = json_decode($responseJson);
12
13if ($response->status == 'OK') {
14    $latitude = $response->results[0]->geometry->location->lat;
15    $longitude = $response->results[0]->geometry->location->lng;
16
17    echo 'Latitude: ' . $latitude;
18    echo '<br />';
19    echo 'Longitude: ' . $longitude;
20} else {
21    echo $response->status;
22    var_dump($response);
23}    
24?>
Annemarie
01 Feb 2020
1
2
3<!DOCTYPE html>
4
5<html>
6
7<form method="post">
8
9<input type="text" name="address">
10
11<input type="submit" name="submit" value="submit">
12
13</form>
14
15</html>
16
17<?php
18
19if(isset($_POST['submit']))
20
21{
22
23
24function getLatLong($address){
25
26    if(!empty($address)){
27
28        //Formatted address
29
30        $formattedAddr = str_replace(' ','+',$address);
31
32        //Send request and receive json data by address
33
34        $geocodeFromAddr = file_get_contents
35('http://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false'); 
36
37        $output = json_decode($geocodeFromAddr);
38
39        //Get latitude and longitute from json data
40
41        $data['latitude']  = $output->results[0]->geometry->location->lat; 
42
43        $data['longitude'] = $output->results[0]->geometry->location->lng;
44
45        //Return latitude and longitude of the given address
46
47        if(!empty($data)){
48
49            return $data;
50
51        }else{
52
53            return false;
54
55        }
56
57    }else{
58
59        return false;  
60 
61    }
62
63}
64
65$address = $_POST['address'];
66
67$latLong = getLatLong($address);
68
69$latitude = $latLong['latitude']?$latLong['latitude']:'Not found';
70
71$longitude = $latLong['longitude']?$latLong['longitude']:'Not found';
72
73echo "Latitude:".$latitude."<br>";
74
75echo "longitude:".$longitude."";
76
77}
78
79?>
80
queries leading to this page
how to get complete address from latitude and longitude in phpget latitude and longitude from address phpconvert address to lat long in phpgrab latitude and longitude in phpget longitude latitude phpget latitude and longitude phpphp address to latlong 27get state from latitude and longitude phplongitude and latitude phphow to get lat long from address phpget address from latitude and longitude phpget longitude and latitude gps phpphp json lat and longitudehow to get latitude and longitude in phpreturn latitude and longitude using phpget the latitude and longitude from phpget the lat long of an address phpget lat long from address phpget lat long from address google api phpget lat lng from address phpphp get latitude and longitude from locationhow to get latitude and longitude from address in phphow to get latitude and longtitude in phpget latitude and longitude from address using phpget longitude and latitude using phpwith latitude and longitude data find address using phphow to get latitude and longitude from form in php get latitude and longitude in phpget latitude and longitude with phpphp get long and latitudehow to get lat long from address in phplatitude longitude phphow to get current location latitude and longitude in phpget longitude and latitude phpphp get latitude longitudeget latitude and longitude from city name in phphow to get lat and long from address in phpget the latitude and logtuide phpget address coordinates phphow we find lat long from address in phpphp get lat long from google mapsget lat long from postcode phpget lat long from ip address phpget city name from latitude and longitude in phphow to get longitude and latitude in phpgoogle map api get latitude and longitude from address in phpget current latitude and longitude in php to input feildphp get lat long from addressget the address from a lat lng phpget lat long from google maps phpphp get lat and lng by addressphp get current location latitude longitudephp code to get address from latitude and longitudeaddress to latitude and longitude phpphp get latitude and longitude from addressget lat long using phplatitude longitude validation in phpphp get longitude and latitudephp get latlong from addressget location from latitude and longitude phpconvert address to lat long phpget latitude and longitude from address in php convert address to lat long using phpconvert lat long into address in phpget longitude and latitude from address in phptype place and get latitude and longitude php functionget longitude and latitude in phpget lat long from address php