我正在使用谷歌地图开发一个应用程序。在此我想在经度纬度值获取表单服务器的位置显示标记。如何在此获取的经度和纬度值显示标记? 以下代码成功从我的服务器获取经度和纬度值,我想在谷歌地图上显示带有此获取的纬度和纬度的标记。我该怎么办?
$data
答案 0 :(得分:1)
为什么您注释掉了添加标记的代码? 试试这个:
// Storing JSON item in a Variable
String lat = c.getString(TAG_LAT);
String longt = c.getString(TAG_LONG);
//Set JSON Data in TextView
tv_latitude.setText(lat);
tv_longitude.setText(longt);
//Parse data to double
double latD = Double.parseDouble(lat);
double longtD = Double.parseDouble(longt);
MarkerOptions marker = new MarkerOptions().position(new LatLng(latD, longtD)).title("point");
googleMap.addMarker(marker);
答案 1 :(得分:0)
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng sydney = new LatLng(-33.867, 151.206);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
googleMap.addMarker(new MarkerOptions().title("Sydney").snippet("The most populous city in Australia.").position(sydney));
}
答案 2 :(得分:0)
你必须使用: GoogleMap.addMarker(的MarkerOptions); 看这个网站和这个问题还: http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html
答案 3 :(得分:0)
这是演示类,使用它可以将Marker添加到给定的lat和long。
public class ListViewAndroidExample extends Activity {
ListView listView ;
int flag=0;//parent
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view_android_example);
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list);
// Defined Array values to show in ListView
String[] values_parent = new String[] { "Android List View",
"Adapter implementation",
"Simple List View In Android",
"Create List View Android",
"Android Example",
"List View Source Code",
"List View Array Adapter",
"Android Example List View"
};
String[] values_child= new String[] { "Child 1",
"Child 2",
"Child 3",
"Child 4"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values_parent);
// Assign adapter to ListView
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
if(flag=0)
{
flag=1;
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values_child);
}
else
{
flag=0;
}
}
});
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if(flag=0)
finish();
else{
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values_parent);
}
}
}
}