gpt4 book ai didi

java - 从数据库获取点到 map android

转载 作者:行者123 更新时间:2023-12-02 13:38:12 24 4
gpt4 key购买 nike

我想显示我的数据库中的标记来映射 Android,但它是我的五个空白页,我能做什么,已经 3 周了,我一直坚持这个!!!帮助!这是开始我的项目的第一步。我的主要 Activity

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>

我的 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"/>

最佳答案

转至您的云控制台>API 管理器> 凭据>您的 MapAPI 如果您没有,则只需创建一个即可。

使用以下方法获取包哈希:

keytool -list -v -keystore mystore.keystore

确保输入正确的包名称和 SHA-1。

注意是的,您必须为调试应用程序和发布应用程序设置 2 个不同的 SHA

关于java - 从数据库获取点到 map android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42880302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com