Street Address to Geolocation Lat/Long

How to get complete address from latitude and longitude?

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());

addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5

String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL

For more info of available details, Look at Android-Location-Address

How to obtain longitude and latitude for a street address programmatically (and legally)

The term you're looking for is geocoding and yes Google does provide this service.

  • New V3 API: http://code.google.com/apis/maps/documentation/geocoding/

  • Old V2 API: http://code.google.com/apis/maps/documentation/services.html#Geocoding

Get full address details based on current location's latitude and longitude in Flutter

Using Geocoder plugin you can get address from the latitiude and longitude

 import 'package:location/location.dart';
import 'package:geocoder/geocoder.dart';
import 'package:flutter/services.dart';

getUserLocation() async {//call this async method from whereever you need

LocationData myLocation;
String error;
Location location = new Location();
try {
myLocation = await location.getLocation();
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'please grant permission';
print(error);
}
if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'permission denied- please enable it from app settings';
print(error);
}
myLocation = null;
}
currentLocation = myLocation;
final coordinates = new Coordinates(
myLocation.latitude, myLocation.longitude);
var addresses = await Geocoder.local.findAddressesFromCoordinates(
coordinates);
var first = addresses.first;
print(' ${first.locality}, ${first.adminArea},${first.subLocality}, ${first.subAdminArea},${first.addressLine}, ${first.featureName},${first.thoroughfare}, ${first.subThoroughfare}');
return first;
}

EDIT

Please use Geocoding instead of Geocoder as Geocoding is maintained by baseflow.com agency.

How can I get city name from a latitude and longitude point?

This is called Reverse Geocoding

  • Documentation from Google:

    http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding.

  • Sample Call to Google's geocode Web Service:

    http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&key=YOUR_KEY

Obtain coordinates from an address flutter

Here created an Input Text Widget and when user taps on it. This takes to google autocomplete screen, where user inputs the location.

TextFormField(
decoration: new InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15),
hintText: Strings.enter_your_house_number_street_etc,
hintStyle: TextStyle(
fontSize: 14,
color: AppColor.grey,
fontFamily: "Open Sans",
fontWeight: FontWeight.normal
)),
maxLines: 1,
controller: _address,
onTap: ()async{
// then get the Prediction selected
Prediction p = await PlacesAutocomplete.show(
context: context, apiKey: kGoogleApiKey,
onError: onError);
displayPrediction(p);
},
)

Here it is getting the lat and long of entered location.

Future<Null> displayPrediction(Prediction p) async {
if (p != null) {
PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);

var placeId = p.placeId;
lat = detail.result.geometry.location.lat;
long = detail.result.geometry.location.lng;

var address =detail.result.formattedAddress;

print(lat);
print(long);
print(address);

setState(() {
_address.text = address;
});
}
}

import 'package:flutter_google_places/flutter_google_places.dart';

How to convert address (as text) to gps coordinates?

The process is called of converting address to geographic coordinates is called geocoding.

Depending on how you'll be using the data, there's an API available from Google, details here. Good luck!

Finding nearest street given a lat-long location

You can use the Google Maps Geocoding API which does exactly that: https://developers.google.com/maps/documentation/geocoding/intro

Take a look at the "Reverse Geocoding" section.

Javascript geocoding from address to latitude and longitude numbers not working

Try using this instead:

var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();

It's bit hard to navigate Google's api but here is the relevant documentation.

One thing I had trouble finding was how to go in the other direction. From coordinates to an address. Here is the code I neded upp using. Please not that I also use jquery.

$.each(results[0].address_components, function(){
$("#CreateDialog").find('input[name="'+ this.types+'"]').attr('value', this.long_name);
});

What I'm doing is to loop through all the returned address_components and test if their types match any input element names I have in a form. And if they do I set the value of the element to the address_components value.

If you're only interrested in the whole formated address then you can follow Google's example



Related Topics



Leave a reply



Submit