gpt4 book ai didi

java - 在 Android Mapsforge map 上添加多个标记

转载 作者:行者123 更新时间:2023-11-29 21:07:36 26 4
gpt4 key购买 nike

请帮助我进行android编程。我正在制作一个 android mapsforge 应用程序,并希望使用 Mysql 在 Android Mapsforge map 上添加多个标记。我的数据位于数据库 Mysql 中,我正在使用 php 获取 Json。它正在工作,但问题是添加标记。这是我的代码:

public void friend_finder(){

try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://fifauz.com/selectall.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

Log.e("log_tag", "connection success ");
Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_SHORT).show();
} catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_SHORT).show();
}
//convert response to string
try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
Intent i = new Intent(getBaseContext(),MainActivity.class);
startActivity(i);
}
is.close();

result=sb.toString();
}
catch(Exception e)
{
Log.e("log_tag", "Error converting result "+e.toString());
}

try {
JSONArray jArray = new JSONArray(result);

for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
String name = json_data.getString("Name");
//Double lati = json_data.getDouble("latitude");
// Double longi = json_data.getDouble("longitude");
String lati = json_data.getString("Lati");
String longi = json_data.getString("Long");
String s = name + lati + longi;
double lati_d = Double.valueOf(lati.trim()).doubleValue();
double longi_d = Double.valueOf(longi.trim()).doubleValue();

Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
ListOverlay listOverlay = new ListOverlay();
GeoPoint currentLocation = new GeoPoint(lati_d,longi_d);
//String marker;
//String m = marker + String.valueOf(i);
Marker marker = createMarker(R.drawable.person, currentLocation);

List<OverlayItem> overlayItems = listOverlay.getOverlayItems();
overlayItems.add(marker);
mapView.getOverlays().add(listOverlay);
}

} catch (Exception e)
{
Log.e("log_tag", "Error converting result "+e.toString());
}
{
// TODO: handle exception
}

}

private Marker createMarker(int resourceIdentifier, GeoPoint geoPoint) {
Drawable drawable = getResources().getDrawable(resourceIdentifier);
return new Marker(geoPoint, Marker.boundCenterBottom(drawable));
}

最佳答案

您也可以通过这种方式在 mapsforge map 中添加标记。

private void createPositionMarker(double paramDouble1, double paramDouble2)
final LatLong localLatLong = new LatLong(paramDouble1, paramDouble2);
TappableMarker positionmarker = new TappableMarker(R.drawable.destination, localLatLong);
mapView.getLayerManager().getLayers().add(positionmarker);
}


private class TappableMarker extends Marker{
public TappableMarker(int icon, LatLong localLatLong) {
super(localLatLong,AndroidGraphicFactory.convertToBitmap(MainActivity.this.getApplicationContext().getResources().getDrawable(icon)),
1*(AndroidGraphicFactory.convertToBitmap(MainActivity.this.getApplicationContext().getResources().getDrawable(icon)).getWidth())/2,
-1*(AndroidGraphicFactory.convertToBitmap(MainActivity.this.getApplicationContext().getResources().getDrawable(icon)).getHeight())/2);
}
}

关于java - 在 Android Mapsforge map 上添加多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24027943/

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