【发布时间】:2014-06-01 06:42:02
【问题描述】:
我正在谷歌地图上开发一个应用程序。我是使用谷歌地图 API V2 的新手。我想单击地图上的位置并获取该位置的地址,我使用 Geocoder,它适用于我,但在不同版本的 android 上它不起作用,所以我想使用 json 任何人帮助我..
Mainactivity.java
@Override
public void onMapLongClick(LatLng point) {
lat = point.latitude;
lng = point.longitude;
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);
sb.append(address.getCountryName()).append(", ");
sb.append(address.getLocality()).append(", ");
sb.append(address.getSubLocality()).append("\n");
sb.append(address.getFeatureName()).append(", ");
sb.append(address.getPostalCode()).append(", ");
sb.append(address.getAdminArea()).append(", ");
sb.append(address.getPhone()).append("");
}
addressString = sb.toString();
mTapTextView.setText(addressString);
} catch (IOException e) {}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.googlemaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.googlemaps.Main"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC9yx6mNQGAIQv9GNAPIMXRYaxWhWwMJ2c" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.googlemaps.ShowDirection"
android:label="@string/title_activity_show_direction"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
</application>
</manifest>
【问题讨论】:
-
你拿什么来获取json??
-
不知道 json Achilles
标签: android json google-maps reverse-geocoding