Created
March 27, 2017 09:16
-
-
Save prasad091/f160cb18386fb549f651be79d7d65679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compile 'com.google.android.gms:play-services:9.6.1' | |
ArrayList<LatLng> locationLatLong = null; | |
public void getLocationLatLon(String locationName) { | |
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
// TODO: Consider calling | |
// ActivityCompat#requestPermissions | |
// here to request the missing permissions, and then overriding | |
// public void onRequestPermissionsResult(int requestCode, String[] permissions, | |
// int[] grantResults) | |
// to handle the case where the user grants the permission. See the documentation | |
// for ActivityCompat#requestPermissions for more details. | |
return; | |
} | |
if (Geocoder.isPresent()) { | |
try { | |
Geocoder gc = new Geocoder(this, Locale.getDefault()); | |
List<Address> addresses = gc.getFromLocationName(locationName, 5); | |
if (addresses != null && addresses.size() > 0) { | |
locationLatLong = new ArrayList<>(addresses.size()); | |
for (Address a : addresses) { | |
if (a.hasLatitude() && a.hasLongitude()) { | |
locationLatLong.add(new LatLng(a.getLatitude(), a.getLongitude())); | |
} | |
} | |
} | |
} catch (IOException e) { | |
// handle the exception | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment