Quiero mostrar marcas de mi base de datos para mapear Android, pero son cinco una página en blanco. Es el primer paso para comenzar mi proyecto. MI ACTIVIDAD PRINCIPAL

public class MainActivity extends FragmentActivity {

// Google Map
private GoogleMap googleMap;

// Latitude & Longitude
private Double Latitude = 0.00;
private Double Longitude = 0.00;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //*** Permission StrictMode
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new   StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    ArrayList<HashMap<String, String>> location = null;
    String url = "http://192.168.1.3:80/pfe/getlatLon.php";
    try {

        JSONArray data = new JSONArray(getHttpGet(url));

        location = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map;

        for(int i = 0; i < data.length(); i++){
            JSONObject c = data.getJSONObject(i);

            map = new HashMap<String, String>();
            map.put("LocationID", c.getString("LocationID"));
            map.put("Latitude", c.getString("Latitude"));
            map.put("Longitude", c.getString("Longitude"));
            map.put("LocationName", c.getString("LocationName"));
            location.add(map);

        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // *** Display Google Map
    googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap)).getMap();
    // *** Focus & Zoom

    Latitude =  Double.parseDouble(location.get(0).get("Latitude").toString());
     Longitude = Double.parseDouble(location.get(0).get("Longitude").toString());
    LatLng coordinate = new LatLng(Latitude, Longitude);
     googleMap.setMapType(com.google.android.gms.maps.GoogleMap.MAP_TYPE_HYBRID);
    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinate, 17));

    // *** Marker (Loop)
    for (int i = 0; i < location.size(); i++) {
        Latitude = Double.parseDouble(location.get(i).get("Latitude").toString());
        Longitude =  Double.parseDouble(location.get(i).get("Longitude").toString());
        String name = location.get(i).get("LocationName").toString();
        MarkerOptions marker = new MarkerOptions().position(new  LatLng(Latitude, Longitude)).title(name);
        googleMap.addMarker(marker);
    }

}

 public static String getHttpGet(String url) {
    StringBuilder str = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) { // Download OK
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                str.append(line);
            }
        } else {
            Log.e("Log", "Failed to download result..");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return str.toString();
}

}

MY MANIFEST:




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chaima.myapplicationpfe2">


<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.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <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.geo.API_KEY"
        android:value="AIzaSyC_VseeYaw_PHdYFT4t8L1xIV0tIBszEvI" />
</application> 

</manifest>

MI XML:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/googleMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>


MY GRADLE:





<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/googleMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
0
ChaimLa 19 mar. 2017 a las 00:51

2 respuestas

La mejor respuesta

Vaya a su cloud console>API manager> Credentials>your MapAPI si no tiene uno, simplemente cree uno.

Obtenga su paquete Hash usando:

keytool -list -v -keystore mystore.keystore

Asegúrese de poner el Package name correcto y SHA-1.

Nota Sí, debe poner 2 SHA diferentes para su aplicación de depuración y su aplicación de lanzamiento

1
MohammedAlSafwan 18 mar. 2017 a las 22:28

Me gusta mUhammad say ... verifique el paquete y la clave de la API ... este es todo el código ... puede usarlo: D

0
ChaimLa 18 mar. 2017 a las 22:25