为什么我的lat lng变量无缘无故地变为(0.0,0.0)

时间:2017-02-27 19:14:57

标签: android google-maps

我从Json那里得到了我的坐标,我在这些坐标上放了一个标记,我确实得到它们3次,它确实向我显示了它所假设的标记但是第四次改变为(0.0,0.0)我不知道为什么。它不会抛出任何错误,只是将标记位置更改为(0.0,0.0)

public class BusinessPremium extends AppCompatActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    String longitude,latitude;
    LatLng durango = new LatLng(0.0,0.0);

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_premium);
        SupportMapFragment supportFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

        supportFragment.getMapAsync(this);

        Bundle bundle=getIntent().getExtras();
        int value=bundle.getInt("no");

        new PlifRequestBase(BusinessPremium.this)
        {

            @Override
            public JsonObject onHttpOk(JsonObject response) throws JSONException
            {
                JsonObject data, details, location, geolocation, more, phoneNumber;
                JsonArray branches, phones;
                data = response;

                branches = data.get("branches").getAsJsonArray();
                details = branches.get(0).getAsJsonObject();
                location = details.get("location").getAsJsonObject();
                geolocation = details.get("geolocation").getAsJsonObject();

                phones = details.get("phones").getAsJsonArray();
                more = phones.get(0).getAsJsonObject();
                //phoneNumber = more.get("number").getAsJsonObject();

                //ids = data.get("id").getAsInt();
                final String name = data.get("name").getAsString();
                final String description = data.get("description").getAsString();
                final String category_image_cover = data.get("category_image_cover").getAsString();
                final String category_image_logo = data.get("category_image_logo").getAsString();
                final String street = location.get("street").getAsString();
                final String number = location.get("number").getAsString();
                final String neighborhood = location.get("neighborhood").getAsString();
                final String zip = location.get("zip").getAsString();
                final String municipality = location.get("municipality").getAsString();
                final String numberP = more.get("number").getAsString();
                latitude = geolocation.get("lat").getAsString();
                longitude = geolocation.get("lng").getAsString();

                durango=new LatLng(Double.parseDouble(latitude),Double.parseDouble(longitude));

                final TextView txtName = (TextView) findViewById(R.id.nameBusiness);
                final TextView txtDescription = (TextView) findViewById(R.id.description);
                final ImageView txtCategory_image_cover = (ImageView) findViewById(R.id.coverBusiness);
                final ImageView txtCategory_image_logo = (ImageView) findViewById(R.id.logoBusiness);
                final TextView txtAddress = (TextView) findViewById(R.id.address);
                final TextView txtPhone = (TextView) findViewById(R.id.phone);

                BusinessPremium.this.runOnUiThread(new Runnable()
                {
                    public void run()
                    {
                        txtName.setText(name);
                        txtDescription.setText(description);
                        Glide.with(BusinessPremium.this).load(category_image_cover).into(txtCategory_image_cover);
                        Glide.with(BusinessPremium.this).load(category_image_logo).into(txtCategory_image_logo);
                        txtAddress.setText(street + " " + number + "\n" + neighborhood + " " + zip + " " + municipality);
                        txtPhone.setText(numberP);
                    }

                });
               // Log.d("ID", String.valueOf(card));
                Log.d("Nombre", name);
                return data;
            }

            @Override
            public void onHttpCreate(JsonObject response) throws JSONException
            {

            }
        }.execute("businesses/" + String.valueOf(value), "GET");
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add marker in Durango and move the camera
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(durango ,17));
        Log.d("adsadads",String.valueOf(durango));

        if (mMap != null) {
            Marker marker = mMap.addMarker(new MarkerOptions().position(durango).title("Marker in Durango"));
        }
    }

0 个答案:

没有答案