[英]Google Map is getting loaded but marker is not getting shown on the map in android native app
[英]map not shown in my android app
我尝试显示一个谷歌地图到它的纬度和经度是+ 34°6'46.53“,+ 35°39'1.04的位置,并构建此代码
public class conactus extends Activity {
//instance variables for Marker icon drawable resources
private int userIcon;
//the map
private GoogleMap theMap;
//user marker
private Marker userMarker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connectus);
//get drawable IDs
userIcon = R.drawable.yellow_point;
//find out if we already have it
if(theMap==null){
//get the map
theMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
//check in case map/ Google Play services not available
if(theMap!=null){
//ok - proceed
theMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
//update location
updatePlaces();
}
}
}
private void updatePlaces(){
//get last location
double lat = 34.112924;
double lng = 35.650288;
//create LatLng
LatLng lastLatLng = new LatLng(lat, lng);
//remove any existing marker
if(userMarker!=null) userMarker.remove();
//create and set marker properties
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
//move to location
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 3000, null);
}
}
但是当我在真实设备上运行应用程序并且在设备上激活Google Play服务后,我没有显示带有logcat的地图
09-06 16:13:30.609: I/Google Maps Android API(18952): Failed to contact Google servers. Another attempt will be made when connectivity is established.
09-06 16:13:30.629: E/Google Maps Android API(18952): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
1.尝试添加以下权限
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
2. After changing API key
AndroidManifest.xml
After changing API key
, 必须 Clear Application Data
清除应用程序数据:
要么去Settings>Application Manager>Select Your Application > Click on Clear Data
或 Must Uninstall The Application
在installing it !
前Must Uninstall The Application
installing it !
注意除非您Completely Uninstall the Application
以clear its Data completely
否则请不要Re-install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.