我有一个显示Google地图的代码,用户可以通过点击地图来查看位置的地址。当我第一次在手机上运行该软件时,它可以工作。但是,当我更改软件外观时,例如更改软件应用程序图标的图像时,就不像第一个了。显示地图但是点击地图不会显示地址。另外,如果我用相同的代码创建新项目,则第一次可以正常工作。但是从接下来的几次开始,它只会显示地图。
package com.example.ghappmgis4;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class GoogleSatelliteMapShow extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google_satellite_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.googlesatellitemap);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng Tehran = new LatLng(35, 51);
mMap.addMarker(new MarkerOptions().position(Tehran).title("ایران"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(Tehran));
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.setOnMapClickListener((new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
//Toast.makeText(getBaseContext(), " click", Toast.LENGTH_SHORT).show();
Log.d("DEBUG","Map clicked[" + point.latitude + "/" + point.longitude + "]");
Geocoder geoCoder= new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(point.latitude, point.longitude, 1);
String add = "";
if (addresses.size() > 0) {
/**for (int i = 0; i < addresses.get(0).getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i)+" ";**/
add += addresses.get(0).getCountryName()+" ";
add += addresses.get(0).getAddressLine(0)+" ";
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
}
catch (IOException e){
e.printStackTrace();
}
}
}));
}
public boolean onKeyDown(int keyCode, KeyEvent event){
switch (keyCode) {
case KeyEvent.KEYCODE_3:
mMap.animateCamera(CameraUpdateFactory.zoomIn());
break;
case KeyEvent.KEYCODE_1:
mMap.animateCamera(CameraUpdateFactory.zoomOut());
break;
}
return super.onKeyDown(keyCode,event);
}
}
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/googlesatellitemap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:uiZoomControls="true"
tools:context=".GoogleSatelliteMapShow"
06-16 00:13:27.573 30458-30458/com.example.ghappmgis4 D/DEBUG: Map clicked[2.8225890364293718/51.04967750608921]
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: java.io.IOException: grpc failed
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at android.location.Geocoder.getFromLocation(Geocoder.java:136)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.example.ghappmgis4.GoogleSatelliteMapShow$1.onMapClick(GoogleSatelliteMapShow.java:63)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.android.gms.maps.zzy.onMapClick(Unknown Source)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.android.gms.maps.internal.zzak.dispatchTransaction(Unknown Source)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at android.os.Binder.transact(Binder.java:380)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at hn.b(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):14)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.android.gms.maps.internal.av.a(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):4)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.maps.api.android.lib6.gmm6.api.aa.b(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):8)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.maps.api.android.lib6.gmm6.vector.ah.b(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):132)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.maps.api.android.lib6.gmm6.vector.da.onSingleTapConfirmed(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):22)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.maps.api.android.lib6.impl.gesture.a.onSingleTapConfirmed(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):240)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.google.maps.api.android.lib6.impl.gesture.c.handleMessage(:com.google.android.gms.dynamite_mapsdynamite@17528027@17.5.28 (020300-252519129):9)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at android.os.Looper.loop(Looper.java:135)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5257)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at java.lang.reflect.Method.invoke(Native Method)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
06-16 00:13:27.943 30458-30458/com.example.ghappmgis4 W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
06-16 00:13:27.953 30458-30458/com.example.ghappmgis4 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
06-16 00:13:33.863 30458-30475/com.example.ghappmgis4 I/art: Explicit concurrent mark sweep GC freed 3664(144KB) AllocSpace objects, 0(0B) LOS objects, 56% free, 9MB/21MB, paused 1.489ms total 58.644ms