Java 救命啊!向maps api v2添加多个标记
编辑 我看到我正在覆盖我的lat long值,直到它们到达onPostExecute。有人建议我在传递到onPostExecute之前使用数组来存储信息。我认为数组每个索引只能容纳1个对象。既然我想在每个索引中保留多个联系人项目(电话、地址、电子邮件等),我该怎么办?例如,对于每个标记点,我不仅要提取lat long值,还要提取要添加到标记的名称 /编辑 我正试图通过MapsAPIv2添加多个标记。我通过JSON字符串提取地址。当我运行它时,我只得到最后一个在地图上显示为标记的地址。如何更改下面的循环以使其显示每个标记。(添加标记位于onPostExecute中)谢谢Java 救命啊!向maps api v2添加多个标记,java,android,google-maps,Java,Android,Google Maps,编辑 我看到我正在覆盖我的lat long值,直到它们到达onPostExecute。有人建议我在传递到onPostExecute之前使用数组来存储信息。我认为数组每个索引只能容纳1个对象。既然我想在每个索引中保留多个联系人项目(电话、地址、电子邮件等),我该怎么办?例如,对于每个标记点,我不仅要提取lat long值,还要提取要添加到标记的名称 /编辑 我正试图通过MapsAPIv2添加多个标记。我通过JSON字符串提取地址。当我运行它时,我只得到最后一个在地图上显示为标记的地址。如何更改下面
public类EndpointsTask扩展异步任务{
公共长文档背景(上下文…上下文){
Contactinfoendpoint.Builder endpointBuilder=新建Contactinfoendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
新JacksonFactory(),
新的HttpRequestInitializer(){
公共无效初始化(HttpRequest HttpRequest){}
});
Contactinfoendpoint=CloudEndpointUtils.updateBuilder(
endpointBuilder.build();
试一试{
字符串apples=endpoint.listContactInfo().execute().toString();
JSONObject jObject=新的JSONObject(苹果);
JSONArray jsonArr=jObject.getJSONArray(“项目”);
对于(int i=0;i您只获得最后一个位置,因为每次在到达onPostExecute之前覆盖lati
和longi
您需要将点存储在数组或其他东西中,然后将它们返回到onPostExecute您可以发布JSON片段吗?我想将每个标记的标题设置为每个联系人的名称。如何在数组中保留联系人项以及新的lat long值?创建一个对象并返回该对象的数组所有的信息
public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
public Long doInBackground(Context... contexts) {
Contactinfoendpoint.Builder endpointBuilder = new Contactinfoendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(),
new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) { }
});
Contactinfoendpoint endpoint = CloudEndpointUtils.updateBuilder(
endpointBuilder).build();
try {
String apples = endpoint.listContactInfo().execute().toString();
JSONObject jObject = new JSONObject(apples);
JSONArray jsonArr = jObject.getJSONArray("items");
for(int i =0 ; i<jsonArr.length() ;i++ ){
JSONObject jsonObj1 = jsonArr.getJSONObject(i);
// Storing each json item in variable
String id = jsonObj1.getString(TAG_ID);
String nameFirst1 = jsonObj1.getString(TAG_FIRSTNAME);
String nameLast1 = jsonObj1.getString(TAG_LASTNAME);
String emailAddress1 = jsonObj1.getString(TAG_EMAIL);
String streetAddress1 = jsonObj1.getString(TAG_ADDRESS);
String phone1 = jsonObj1.getString(TAG_PHONE);
//test to see if made it to string
Log.d("YOUR_TAG", "First Name: " + nameFirst1 + " Last Name: " + nameLast1);
address = coder.getFromLocationName(streetAddress1,5);
Address location1 = address.get(0);
// SET LAT LNG VALUES FOR MARKER POINT
lati = location1.getLatitude();
longi = location1.getLongitude();
Log.d("Location", "Location:" + lati + " " + longi);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (long) 0;
}
// ADD MARKER TO MAP UI
protected void onPostExecute(Long result) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(lati, longi))
.title("Hello world"));
}
}