android - Double values for Longitude and Latitude not passing to googlemap Marker -
i have dataobject contains longs latitude , longitude. passing these method in fragment, calls parent activity method show googlemap.
the problem is, longitude , latitude keep resulting (0,0). have checked object setting , getting correct figures.
the figures correct in fragment , in call showmap, marker keeps showing default 0,0.
i have map in activity xml, within framelayout, change visibility. (i think problem, it's blank map)
i have spent hours on this, , have come here, cap in hand.
this relevant parts of code:
my fragment code:
/** * latitude , longitude dataobject , pass * showmap method of activity. */ public void showmap() { double lat = dataobject.getlatitude(); double long_ = dataobject.getlongitude(); string name = dataobject.getname(); ((myactivity) getactivity()).showmap(lat, long_, name); }
my activity code:
public void showmap(double lat, double _long, string _title) { googlemap googlemap = ((mapfragment) getfragmentmanager(). findfragmentbyid(r.id.map)).getmap(); googlemap.setmaptype(googlemap.map_type_hybrid); marker marker = googlemap.addmarker(new markeroptions() .position(new latlng(lat, _long)).title(_title)); googlemap.movecamera(cameraupdatefactory.zoomto(5f)); }
my activity xml:
<relativelayout style="@style/rlayout1" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my"> .... <framelayout android:visibility="gone" ... <fragment android:id="@+id/map" android:layout_height="match_parent" android:layout_width="match_parent" android:name="com.google.android.gms.maps.mapfragment"/>
i figure i'm missing essential, can't figure out is.
adding logs:
googlemap googlemap = ((mapfragment) getfragmentmanager(). findfragmentbyid(r.id.map)).getmap(); //log. log.d("1. act lat="+string.valueof(lat),"act long="+string .valueof(_long) ); googlemap.setmaptype(googlemap.map_type_hybrid); //log. log.d("2. act lat=" + string.valueof(lat), "act long=" + string.valueof(_long)); marker marker = googlemap.addmarker(new markeroptions() .position(new latlng(lat, _long)).title(_title)); //log. log.d("3. act lat="+string.valueof(lat),"act long="+string .valueof(_long) ); googlemap.movecamera(cameraupdatefactory.zoomto(5f)); //log. log.d("4. act lat="+string.valueof(lat),"act long="+string .valueof(_long) ); framelayout framelayout = (framelayout) findviewbyid(r.id.third); log.d("5. act lat="+string.valueof(lat),"act " + "long="+string .valueof(_long) ); framelayout.setvisibility(view.visible); log.d("6. act lat=" + string.valueof(lat), "act long=" + string.valueof(_long));
07-09 05:57:37.147 32317-32317/thiscode.databasedemo d/1. act lat=-42.9﹕ act long=147.3 07-09 05:57:37.157 32317-32317/thiscode.databasedemo d/2. act lat=-42.9﹕ act long=147.3 07-09 05:57:37.167 32317-32317/thiscode.databasedemo d/3. act lat=-42.9﹕ act long=147.3 07-09 05:57:37.167 32317-32317/thiscode.databasedemo d/4. act lat=-42.9﹕ act long=147.3 07-09 05:57:37.167 32317-32317/thiscode.databasedemo d/5. act lat=-42.9﹕ act long=147.3 07-09 05:57:37.167 32317-32317/thiscode.databasedemo d/6. act lat=-42.9﹕ act long=147.3
after confirming markers getting placed correctly, looks issue getting current view lined correctly.
this should it:
latlng latlng = new latlng(lat, _long); marker marker = googlemap.addmarker(new markeroptions() .position(latlng).title(_title)); cameraposition cameraposition = new cameraposition.builder() .target(latlng).zoom(5).build(); googlemap.animatecamera(cameraupdatefactory .newcameraposition(cameraposition));
you might need add these imports:
import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.model.cameraposition;
Comments
Post a Comment