Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All
i want to make a page to find Longitude and Latitude of particular place i use google Api on php page for calculate it:
JavaScript
function getLongitude($place)
       {
          $urlc="http://maps.google.com/maps/api/geocode/json?address=".$place."&sensor=false";
          $geocode=file_get_contents($urlc);
	  $output= json_decode($geocode);
	
	$longitude = $output->results[0]->geometry->location->lng;
       return $longitude;
       }
finction getLatitude($place)
        {
        $urlc="http://maps.google.com/maps/api/geocode/json?address=".$place."&sensor=false";
       $geocode=file_get_contents($urlc);
	$output= json_decode($geocode);
	$latitude = $output->results[0]->geometry->location->lat;
        return $latitude;
	}

on the click event on button i want to call calculate()of java script
JavaScript
<script Languge="JavaScript>
function calculate()
 {
   var place= document.zodiac.PlaceOfBirth.value;
   document.zodiac.latitude.value= getLatitude(place)// call php function
   document.zodiac.latitude.value= getLatitude(place)//call php function
}
</script>

kindly help haw can i use php function in java script.
Posted
Updated 11-Aug-11 20:56pm
v2

1 solution

You know, you cannot call directly PHP code from JavaScript, PHP is server side scripting while JavaScript runs on the client. What you can do is, from your JavaScript function, load another page or reload the same page passing a parameter to let the PHP know you need the function call. See, for instance, the following thread[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Aug-11 2:14am    
Agree, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900