Hi everyone,

I need to find the Latitude and Longitude values for a moving vehicle from the Google Maps, using javascripts.

Can you give the sample code, please help me.

Recommended Answers

All 4 Replies

I don't think you can do that, because it is not your page.

And I haven't found a way to find longitude and latitude on Google Maps. They don't display it.

Terraserver displays longitude and latitude:

http://terraserver.microsoft.com

Google Earth displays longitude and latitude, but it is not a website, in the sense that it has it's own dedicated browser.

Look at google maps api - its geo coding service returns lat and long of a point if you feed in an address or postal code.

<?php
$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=Maharajas+College+Cochin&sensor=false');
$output= json_decode($geocode);
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://maps.google.com/maps?file=api&v=1&key=ADD_YOUR_KEY_HERE" type="text/javascript"></script>
</head>

<body>
<div id="map" style="width: 400px; height: 300px"></div>

<script type="text/javascript">
var map = new GMap(document.getElementById("map"));
var point = new GPoint(<?php echo $longitude; ?>,<?php echo $latitude; ?>);
 address = '<?php echo $longitude; ?>  ,<?php echo $latitude; ?>';

var mark = createInfoMarker(point, address);
map.addOverlay(mark);
function createInfoMarker(point, address) {
 var marker = new GMarker(point);
 map.centerAndZoom(point, 3);

 GEvent.addListener(marker, "click",
 function() {
 marker.openInfoWindowHtml(address);


 }
 );
 return marker;
}
</script>

</body>
</html>

Ashishjannela,

If I understand correctly, then you need to read this.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.