How to make the google map in android?
i have make one application for google map.
i am using lattitude and longitude as the position. but i am unable to show the google map,
can anyone help me , whats wrong with my code,
the code is given below:
package com.googlemaps;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.app.Activity;
import android.os.Bundle;
public class GooglemapsActivity extends MapActivity{
/** Called when the activity is first created. */
MapController mControl;
GeoPoint GeoP;
MapView mapV;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapV = (MapView) findViewById(R.id.map开发者_Python百科View);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
double lat = 40.8;
double longi = 96.666;
GeoP = new GeoPoint( (int)(lat * 1E6), (int) (longi * 1E6));
mControl = mapV.getController();
mControl.animateTo(GeoP);
mControl.setZoom(13);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
and the xml file is:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0acFPt8mdFAjqGq9AuToZIgkd4b8jxUM0K8mg0Q"
/>
</LinearLayout>
Your code seems good. Make sure that you have selected a "Google APIs" version instead of an Android version as the "Project Build Target" in your project configuration.
Also, you have to add the following line as a child of your Application element in the AndroidManifest.
<uses-library android:name="com.google.android.maps"/>
And this one as a child of the Manifest element.
<uses-permission android:name="android.permission.INTERNET" />
"got this error "Couldn't get connection factory client " in the logcat, what is the solution for this ?"..Jayesh, this is not a problem as mapView logs this error message every time even when it successfully loads. Each time every time on success. Jayesh, this issue typically happens if you use the debug key in release application. Note that there are two separate keys-1 for debug and another for release. With that said, is this key the debug key or release key?
精彩评论