Ahsan Malik
Ahsan Malik

Reputation: 425

how can i display marker on google map with lat long from response in main same activity

.now i m doing in two activities first get the response from server and then pass lat , longi to another activity where onmapready(); function display the marker on google maps.but i want this in one activity how can i?

enter code here public void onMapReady(GoogleMap map) {
    mMap = map;
   refresh(mMap);

}

private void addMarkersToMap() {
    // Uses a colored icon.
    LatLng sydney = new LatLng(latt, langg);
    mMap.addMarker(new MarkerOptions().position(sydney)
            .title("")
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin)));
   // mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,1));
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(sydney)
            .zoom(17).build();
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

}
private void pointToPosition(LatLng position) {
    //Build camera position
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(position)
            .zoom(17).build();
    //Zoom in and animate the camera.
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}

Upvotes: 0

Views: 79

Answers (2)

vibhal bhatiya
vibhal bhatiya

Reputation: 41

Try this in your OnPostExecute of Async task of your first activity only. Then you don't required other activity.

    @Override
    protected void onPostExecute(String result)
    {
        super.onPostExecute(result);
        // other code for get lat-long
        loadMap();
    }


private void loadMap()
{   
    LatLng sydney = new LatLng(latt, langg);
    mMap.addMarker(new MarkerOptions().position(sydney).title("")
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin)));
    CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(sydney)
        .zoom(17).build();                     

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

Upvotes: 4

Akshay Mahajan
Akshay Mahajan

Reputation: 2200

You can get your map using

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                                 .findFragmentById(R.id.map);
map = mapFragment.getMapAsync(NearestActivity.this);

Then, in your OnPostExecute of Async task,populate map markers using map.addMarker(options).

Upvotes: 0

Related Questions