Skip to main content

Android - Google MAP V2 PART 3 (add Polyline)



Before go ahead Please look in to PART-1 & PART-2

I have just modify Main Activity class:

 package com.djandroid.mapsv2;  
 import android.graphics.Color;  
 import android.os.Bundle;  
 import android.support.v4.app.FragmentActivity;  
 import android.support.v4.app.FragmentManager;  
 import com.google.android.gms.maps.GoogleMap;  
 import com.google.android.gms.maps.GoogleMap.OnMapClickListener;  
 import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;  
 import com.google.android.gms.maps.SupportMapFragment;  
 import com.google.android.gms.maps.model.LatLng;  
 import com.google.android.gms.maps.model.Marker;  
 import com.google.android.gms.maps.model.MarkerOptions;  
 import com.google.android.gms.maps.model.Polyline;  
 import com.google.android.gms.maps.model.PolylineOptions;  
 public class MainActivity extends FragmentActivity {  
      private GoogleMap MAP;  
      private boolean markClick;  
      private PolylineOptions rectoptions;  
      private Polyline poliline;  
      @Override  
      protected void onCreate(Bundle arg0) {  
           // TODO Auto-generated method stub  
           // setTheme(R.style.Theme_Sherlock);  
           super.onCreate(arg0);  
           setContentView(R.layout.activity_main);  
           FragmentManager myFM = getSupportFragmentManager();  
           SupportMapFragment myMAPF = (SupportMapFragment) myFM  
                     .findFragmentById(R.id.fragment1);  
           MAP = myMAPF.getMap();  
           MAP.setMyLocationEnabled(true);  
           MAP.setMapType(GoogleMap.MAP_TYPE_HYBRID);  
           MAP.setOnMapClickListener(new OnMapClickListener() {  
                @Override  
                public void onMapClick(LatLng point) {  
                     // TODO Auto-generated method stub  
                     MAP.addMarker(new MarkerOptions().position(point).title(  
                               point.toString()));  
                }  
           });  
           MAP.setOnMarkerClickListener(new OnMarkerClickListener() {  
                @Override  
                public boolean onMarkerClick(Marker marker) {  
                     // TODO Auto-generated method stub  
                     if (markClick) {  
                          if (poliline != null) {  
                               poliline.remove();  
                               poliline = null;  
                          }  
                          rectoptions.add(marker.getPosition());  
                          rectoptions.color(Color.BLUE);  
                          poliline = MAP.addPolyline(rectoptions);  
                     } else {  
                          if (poliline != null) {  
                               poliline.remove();  
                               poliline = null;  
                          }  
                          rectoptions = new PolylineOptions().add(marker  
                                    .getPosition());  
                          markClick = true;  
                     }  
                     return false;  
                }  
           });  
           markClick = false;  
      }  
 }  

Comments

  1. I have problem getMap() always return null . Can you help me ????

    ReplyDelete
    Replies
    1. download code from here and check

      https://github.com/dhaval0122/AndroidGoogleMapV2

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. working fine this code, i am looking add proximity alert in Google MAPv2 or last version codes will will work have any reference for MAp v2

    ReplyDelete

Post a Comment

Popular posts from this blog

Why Domain-Specific AI Agents Beat One Big Agent

Everyone is building agents right now. Real estate firms. Independent insurance brokers. Fortune 500 companies with budgets big enough to hire an army of consultants. Ask around and you'll hear the same story everywhere: "we're building our own agent." And yet almost nobody is asking the obvious question: why does the default approach keep failing? One large, general-purpose agent gets wired up to every tool the business owns. It impresses in the demo. Then it quietly stalls before production. There's a gap between what businesses want and what they're actually getting. They want AI woven into their data, their workflows, their day-to-day operations. What they get instead is one oversized agent trying to be a sales rep, a compliance officer, and a customer support line, all at once. That gap is an architecture problem, not a model problem. Key Takeaways The default "one big agent" pattern breaks down on context bloat, cost, fragility, and portability...

ANDROID - update status Linked-IN

jars: 1. linkedin-j-android.jar 2. scribe-1.3.1.jar MainActivity: package com.testshare; import java.util.EnumSet; import org.scribe.oauth.OAuthService; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.google.code.linkedinapi.client.LinkedInApiClient; import com.google.code.linkedinapi.client.LinkedInApiClientFactory; import com.google.code.linkedinapi.client.enumeration.NetworkUpdateType; import com.google.code.linkedinapi.schema.Network; public class TestshareActivity extends Activity { private int LINKEDIN_OAUTH_RESULT_CODE = 4000; private OAuthService service; private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(...

Stop Babysitting your AI Coding Agent Every Single Session

  Watched a video by DSquaredLabs on " No more re-explaining: Give your AI agent a memory graph " — here's what stuck with me and why I think this three-tool system is worth your attention If you work on a large codebase with AI coding tools, you already know the ritual. Open a new chat, paste your file structure, explain your stack, describe how the modules connect — and repeat the whole thing tomorrow. It is not a minor inconvenience. It is a compounding productivity tax that gets worse as your project grows. This article breaks down a three-tool system designed to fix exactly that. If you want the full walkthrough with a live demo on a real monorepo, the video at the bottom covers everything in depth — but the core concepts are worth understanding before you dive in. The Problem With How Most Developers Use AI Today Most AI-assisted coding workflows are missing three things that every good engineering team actually has: A map of the codebase A process for how w...