android - Google Map v2: to display multiple locations on Google Maps -
android - Google Map v2: to display multiple locations on Google Maps -
i need point out 5 different locations on google maps. far got output successfully. there no errors in code.
my problem points single location. have points different locations, example, 1 have point chennai , other have point delhi or else.
mainactivity.java:
public class mainactivity extends activity { // google map private googlemap googlemap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); seek { // loading map initilizemap(); googlemap.setmaptype(googlemap.map_type_normal); double latitude[] ={13.07891,13.11602,13.11355,13.12511,13.08367}; double longitude[] = {80.28215,80.23166,80.29613,80.29554,80.23961}; // lets place 10 random markers (int = 0; < 5; i++) { // random latitude , logitude double[] randomlocation = createrandlocation(latitude[i], longitude[i]); // adding marker markeroptions marker = new markeroptions().position( new latlng(randomlocation[0], randomlocation[1])) .title("hello maps " + i); log.e("random", "> " + randomlocation[0] + ", " + randomlocation[1]); // changing marker color if (i == 0) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_azure)); if (i == 1) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_blue)); if (i == 2) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_cyan)); if (i == 3) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_green)); if (i == 4) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_magenta)); googlemap.addmarker(marker); // move photographic camera lastly position zoom level if (i == 4) { cameraposition cameraposition = new cameraposition.builder() .target(new latlng(randomlocation[0], randomlocation[1])).zoom(15).build(); googlemap.animatecamera(cameraupdatefactory .newcameraposition(cameraposition)); } } } grab (exception e) { e.printstacktrace(); } } @override protected void onresume() { super.onresume(); initilizemap(); } /** * function load map if map not created create * */ private void initilizemap() { if (googlemap == null) { googlemap = ((mapfragment) getfragmentmanager().findfragmentbyid( r.id.map)).getmap(); // check if map created or not if (googlemap == null) { toast.maketext(getapplicationcontext(), "sorry! unable create maps", toast.length_short) .show(); } } } /* * creating random postion around location testing purpose */ private double[] createrandlocation(double latitude, double longitude) { homecoming new double[] { latitude + ((math.random() - 0.5) / 500),longitude + ((math.random() - 0.5) / 500),150 + ((math.random() - 0.5) * 10) }; } }
there 5 different marker can see in coding.every marker point out same location.my problem is, need show each , every marker have point out different location.
now seek way
double latitude[] ={13.07891,13.11602,13.11355,13.12511,13.08367}; double longitude[] = {80.28215,80.23166,80.29613,80.29554,80.23961}; // lets place 5 markers (int = 0; < 5; i++) { // adding marker markeroptions marker = new markeroptions().position( new latlng(latitude[i], longitude[i])) .title("hello maps " + i); // changing marker color if (i == 0) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_azure)); if (i == 1) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_blue)); if (i == 2) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_cyan)); if (i == 3) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_green)); if (i == 4) marker.icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_magenta)); googlemap.addmarker(marker); // move photographic camera lastly position zoom level if (i == 4) { cameraposition cameraposition = new cameraposition.builder() .target(new latlng(randomlocation[0], randomlocation[1])).zoom(15).build(); googlemap.animatecamera(cameraupdatefactory .newcameraposition(cameraposition)); } }
android google-maps-android-api-2
Comments
Post a Comment