Android 谷歌地图标记问题

Android 谷歌地图标记问题,android,google-maps,Android,Google Maps,我在试着用一个可以移动的地图标记。但是马克笔甚至没有出现。标记应该在使用我的JSON对象初始化后移动。我的JSON代码在后台每两秒钟更新一次。也许我对JSON对象的处理是错误的 public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private LocationManager locationManager; private GoogleMap mMap; JSONParser

我在试着用一个可以移动的地图标记。但是马克笔甚至没有出现。标记应该在使用我的JSON对象初始化后移动。我的JSON代码在后台每两秒钟更新一次。也许我对JSON对象的处理是错误的

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private LocationManager locationManager;

private GoogleMap mMap;

JSONParser jsonparser = new JSONParser();
private CameraPosition cameraPosition;
private GoogleMap googleMap;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(map);
    List<MarkerOptions> markerOptions = new ArrayList<>();


    Bitmap.Config conf = Bitmap.Config.ARGB_8888;
    Bitmap bmp = Bitmap.createBitmap(200, 50, conf);
    Canvas canvas = new Canvas(bmp);


    mapFragment.getMapAsync(this);


}


/**
 * nnnnnnnnnnn
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
}


private void setUpMap() {
}


class MarkerTask extends AsyncTask<Void, Void, String> {

    private static final String LOG_TAG = "ExampleApp";

    private static final String SERVICE_URL = "http://api.wheretheiss.at/v1/satellites/25544";

    // Invoked by execute() method of this object
    @Override
    protected String doInBackground(Void... args) {

        HttpURLConnection conn = null;
        final StringBuilder json = new StringBuilder();
        try {
            // Connect to the web service
            URL url = new URL(SERVICE_URL);
            conn = (HttpURLConnection) url.openConnection();
            InputStreamReader in = new InputStreamReader(conn.getInputStream());

            // Read the JSON data into the StringBuilder
            int read;
            char[] buff = new char[1024];
            while ((read = in.read(buff)) != -1) {
                json.append(buff, 0, read);
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error connecting to service", e);
            //throw new IOException("Error connecting to service", e); //uncaught
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }

        return json.toString();
    }

    // Executed after the complete execution of doInBackground() method
    @Override
    protected void onPostExecute(String json) {
        JSONParser jsonparser = new JSONParser();
        try {
            // De-serialize the JSON string into an array of city objects

            while (!isCancelled()) {
                JSONObject jsonObj = jsonparser.makeHttpRequest("http://api.wheretheiss.at/v1/satellites/25544");
                ;

                LatLng latLng = new LatLng(jobj.getDouble("longitude"),
                        jobj.getDouble("latitude"));

                //move CameraPosition on first result

                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(latLng).zoom(13).build();

                mMap.animateCamera(CameraUpdateFactory
                        .newCameraPosition(cameraPosition));


                // Create a marker for each city in the JSON data.
                mMap.addMarker(new MarkerOptions()
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
                        .title("International Space Station")
                        .snippet(Integer.toString(jsonObj.getInt("population")))
                        .position(latLng));


            }
        } catch (JSONException e) {
            Log.e(LOG_TAG, "Error processing JSON", e);
        }

    }
}
公共类MapsActivity扩展了FragmentActivity在MapreadyCallback上的实现{
私人场所经理场所经理;
私有谷歌地图;
JSONParser JSONParser=新的JSONParser();
私人摄像位置摄像位置;
私人谷歌地图谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
//获取SupportMapFragment,并在地图准备好使用时收到通知。
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(地图);
List markerOptions=new ArrayList();
Bitmap.Config conf=Bitmap.Config.ARGB_8888;
位图bmp=Bitmap.createBitmap(200,50,conf);
画布=新画布(bmp);
getMapAsync(这个);
}
/**
*nnnnnnnnnnnnnn
*一旦可用,就可以操纵贴图。
*当映射准备好使用时,将触发此回调。
*这是我们可以添加标记或线条、添加侦听器或移动摄影机的地方。在这种情况下,
*我们只是在澳大利亚悉尼附近加了一个标记。
*如果设备上未安装Google Play服务,系统将提示用户安装
*它位于SupportMapFragment内。此方法仅在用户
*已安装Google Play服务并返回应用程序。
*/
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
mMap=谷歌地图;
}
私有void setUpMap(){
}
类MarkerTask扩展了异步任务{
私有静态最终字符串日志\u TAG=“ExampleApp”;
私有静态最终字符串服务\u URL=”http://api.wheretheiss.at/v1/satellites/25544";
//由此对象的execute()方法调用
@凌驾
受保护字符串doInBackground(无效…参数){
HttpURLConnection conn=null;
final StringBuilder json=新StringBuilder();
试一试{
//连接到web服务
URL=新URL(服务URL);
conn=(HttpURLConnection)url.openConnection();
InputStreamReader in=新的InputStreamReader(conn.getInputStream());
//将JSON数据读入StringBuilder
int-read;
char[]buff=新字符[1024];
while((read=in.read(buff))!=-1){
append(buff,0,read);
}
}捕获(IOE异常){
Log.e(日志标签,“连接到服务时出错”,e);
//抛出新IOException(“连接到服务时出错”,e);//未捕获
}最后{
如果(conn!=null){
连接断开();
}
}
返回json.toString();
}
//在完全执行doInBackground()方法后执行
@凌驾
受保护的void onPostExecute(字符串json){
JSONParser JSONParser=新的JSONParser();
试一试{
//将JSON字符串反序列化为城市对象数组
而(!isCancelled()){
JSONObject jsonObj=jsonparser.makeHttpRequest(“http://api.wheretheiss.at/v1/satellites/25544");
;
LatLng LatLng=新LatLng(作业J.getDouble(“经度”),
jobj.getDouble(“纬度”);
//在第一个结果上移动摄影机位置
CameraPosition CameraPosition=新建CameraPosition.Builder()
.target(latLng).zoom(13.build();
mMap.animateCamera(相机更新工厂
.newCameraPosition(cameraPosition));
//在JSON数据中为每个城市创建一个标记。
mMap.addMarker(新标记选项()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
.标题(“国际空间站”)
.snippet(Integer.toString(jsonObj.getInt(“填充”))
.位置(板条);
}
}捕获(JSONException e){
e(Log_标记,“错误处理JSON”,e);
}
}
}

}

您似乎没有执行
MarkerTask
的任何代码。您似乎没有执行
MarkerTask
的任何代码。