Lan/Lat information

Hello guys,

I am integrating google maps into my app and need to know how to get lan/lat information on the fly for a particular address?

Is it possible?

Thanks in advance.

Google Maps can do that for you. Read up on the documentation for it. If you have any specific technical questions, feel free to ask.

I have list of addresses and need to get all the lan/lat for these addresses as I need to save it in my database and then I will be able to show all the lan/lat point at once. Please let me know about it. thank you for the reply

I went through docs but couldn’t find it.

It will be a process from the back-end to save all the lan/lat in my database table.

Please let me know :slight_smile: thanks again

Don’t know about other countries but my experience of Google Maps API for UK postcodes was that, using the API, you would only get a generic central locaton for each postcode and it ignored ther second half of the postcode.

So YO11 1AA and YO11 9ZZ would both get the same location, neither of which would be accurate.

The Google Maps search facility is apparently based on much more accurate info so you type in postcodes to that and get a very accurate location.

I ended up copying those locations using this:
http://www.gorissen.info/Pierre/maps/googleMapLocation.php

to manually find each lat / lon and inserted them into a table and dragged these co-ordinates out for each business id.

Very time consuming so would also be interested to know if there’s a solution I missed.

You do not need to look up and store the latitudes/longitudes. You can add all your addresses as points on the map. Google will figure out the latitude/longitude from the addresses.

There must be a solution to get lan/lat based on address. Currently my script is sending one request a time and as a resut pin is being displayed. there are nearly 35 pins and its taking time. I need to get lan/lat information so that I can place markers ( all at once).

Can you please provide sample code? I would appreciate your help

http://code.google.com/apis/maps/documentation/examples/geocoding-simple.html

var map = new GMap2(document.getElementById(“map_canvas”));
var geocoder = new GClientGeocoder();

function showAddress(address) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}

for one address its fine. I have to show 35 markers and my script is currently calling this

showAddress(address);
showAddress(address);
showAddress(address);
showAddress(address);
.
.
.
showAddress(address); // 35 times.

on Timeinterval which is taking long. I need to place all the markers at once.

Don’t know if this will help any, but I ran into a time issue using the GoogleMaps JS API, so I now grab the address with a PHP object and pass it to my page view AJAX.


class GoogleGeoData {

	private $key = ""; ## GoogleMaps Key

	public $debug = false;

	public function __construct($key = null) {
		if (!is_null($key)) {
			$this->key = $key;
		}
		if (empty($this->key)) {
			$this->_error("You must specify a Google API key to continue.");
		}
		$this->key = rawurlencode($this->key);
	}

	public function fetch($address, $dec = 6) {
		$address = $this->_address($address);
		$api_path = "http://maps.google.com/maps/geo?q=".$address."&output=csv&key=".$this->key;
		if (($result = @file_get_contents($api_path)) === false) {
			return $this->_error("There was an error fetching your request.");
		} else {
			list($code, $prec, $lat, $long) = split(",", $result);
			if ($code != 200) {
				if ($this->debug) {
					return $this->_error("There was an error fetching your request.");
				}
				return false;
			}
			if (empty($lat) || empty($long)) {
				if ($this->debug) {
					return $this->_error("There was an error fetching your request.");
				}
				return false;
			}
		}
		return array(
			rawurldecode($address),
			round($lat, $dec),
			round($long, $dec),
		);
	}

	private function _address($address) {
		$address = str_replace("#", " ", $address);
		$address = preg_replace("/\\s+/", " ", $address);
		$address = preg_replace("/(\\d)(th|st|nd)/i", "$1", $address);
		$address = preg_replace("/unit\\s*\\d+[,\\.]*/i", "", $address);
		$address = rawurlencode($address);
		return $address;
	}

	private function _error($err) {
		trigger_error($err, E_USER_ERROR);
	}
}

I use this object to pull the data, then save it to a database so I wont have to query google twice for the same address.


$geo = new GoogleGeoData();
$result = $geo->fetch("Address");

$lat = $result[1];
$lon = $result[2];

Then pass that to the page via AJAX and have the GoogleMaps API add the marker


var map;

function init() {
	map = new GMap2($("canvas"));
	map.addControl(new GLargeMapControl3D());
	map.addControl(new GMenuMapTypeControl());
}

function addMarker(lat, lng) {
	var point = new GLatLng(lat, lng);
	map.addOverlay(new GMarker(point));
}

Then why are you using a time interval?

This was announced by Google this morning;

This post might put that announcement into perspective for you and also links to what was, until this morning, state of the art (a comparison of 3 other services).

Fast moving stuff this, eh?

oh Wowwww :slight_smile: Thank you all for the response

Wonderful!