Obtain Latitude and Longitude from Address Without the Use of Google API

how to get latitude and longitude for an address WITHOUT using Google's Geocoding services

Correct. Kudos for honoring TOS.

There are other services which perform geocoding. To name a few: Bing, Yahoo, MapQuest, Nominatim. However, these have various Terms of Service restrictions which are similar to Google's that may also apply. If not that, then there are query limits. There's also USC WebGIS, but its demos are frequently down and the service is reportedly intermittent.

The way around the limitations of a lot of these free services is probably to use a commercial service. There are several out there, and each one works a little differently. Some will search for addresses and make a best guess (or approximate) the results -- this is what Google and other search services do.

Others will take an address, suspected to be real, and actually verify it, then geocode it. This leads to potentially more helpful and accurate results because the address is guaranteed to be correct and standardized. In the US, this is called CASS™ processing (though not all vendors will geocode). It's useful for creating perimeters on maps (given a geocoding precision value) and for showing coordinates in the right place instead of a second-best address hundreds of miles away.

One such geocoding service is LiveAddress API. (I work at SmartyStreets.) The demos show how the geocoding works, but it's flexible so you can choose how to implement it with tilemill. Further, there aren't query limits with LiveAddress because the system will scale up based on demand. And you won't pay for addresses which don't validate, which helps prevent abuse.

The choice is yours, depending on your needs. Do a little research and you ought to find something good. Hope this is of some help!

Can I provide addresses instead of latitude and longitude to Google Maps?

Yes of course. That can be done very easily, using the Geocoding Services provided by the Google Maps JavaScript API. Consider the following example:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Geocoding Demo 1</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 400px; height: 300px;"></div>

<script type="text/javascript">

var address = 'London, UK';

var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 6
});

var geocoder = new google.maps.Geocoder();

geocoder.geocode({
'address': address
},
function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
map.setCenter(results[0].geometry.location);
}
});

</script>
</body>
</html>

Screenshot:

Google Maps v3 Geocoding Demo

You can simply substitute 'London, UK' from the address variable to any location that supports geocoding in Google Maps.

How to extract latitude and longitude from Google Maps autocomplete

You can use the Google API to get the Longitude and Latitude from your address.
As you already said, you should implement a hidden field where the result should be inserted.
Then you can save the location together with the coordinates.

I recently implemented this function in one of my projects:

function getLatLngFromAddress(city, country){

var address = city +", "+ country;
var geocoder = new google.maps.Geocoder();

geocoder.geocode( { 'address': address}, function(results, status) {

if (status == google.maps.GeocoderStatus.OK) {
$('#latitude').val(results[0].geometry.location.lat());
$('#longitude').val(results[0].geometry.location.lng());

} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
}

How can I find the latitude and longitude from address?

public GeoPoint getLocationFromAddress(String strAddress) {

Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;

try {
address = coder.getFromLocationName(strAddress, 5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();

p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
(double) (location.getLongitude() * 1E6));

return p1;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

strAddress is a string containing the address. The address variable holds the converted addresses.

Using Address Instead Of Longitude And Latitude With Google Maps API

See this example, initializes the map to "San Diego, CA".

Uses the Google Maps Javascript API v3 Geocoder to translate the address into coordinates that can be displayed on the map.

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var address ="San Diego, CA";
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
if (geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);

var infowindow = new google.maps.InfoWindow(
{ content: '<b>'+address+'</b>',
size: new google.maps.Size(150,50)
});

var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title:address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});

} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%">
</body>
</html>

working code snippet:

var geocoder;
var map;
var address = "San Diego, CA";

function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
if (geocoder) {
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);

var infowindow = new google.maps.InfoWindow({
content: '<b>' + address + '</b>',
size: new google.maps.Size(150, 50)
});

var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});

} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
}
<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas" ></div>


Related Topics



Leave a reply



Submit