我正在一个Android项目上,我想在Google Map上的2点之间绘制路线。我已经成功绘制了源和目的地之间的路线。但是我有一个问题,即有时候我想在两个以上的点之间绘制一条路径,那时候我编写的代码正在绘制第一个和最后一个位置之间的路径,并离开中点位置。我真正想要的是我的路线应该经过中点到目的地。我该如何实现?
答案 0 :(得分:0)
您可以分别在三个点之间绘制路线。因此,首先绘制从起点到中点的路线,然后从中点到终点。然后,如果要添加所需的标记。
答案 1 :(得分:0)
您可以使用GoogleMaps API Dcoumented Here中的PolylineOptions,并继续添加所有应包含在路线中的点。你可以做这样的事情
import java.util.ArrayList;
import java.util.List;
import org.easymock.EasyMock;
import org.easymock.EasyMockRunner;
import org.easymock.EasyMockSupport;
import org.easymock.Mock;
import org.easymock.TestSubject;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
@RunWith(EasyMockRunner.class)
public class CustomAuthenticationFilterTest extends EasyMockSupport{
@TestSubject
CustomAuthenticationFilter customAuthenticationFilter = new CustomAuthenticationFilter();
@Mock
UsernamePasswordAuthenticationFilter usernamePasswordAuthenticationFilter;
@Test
public void testAttemptAuthentication() throws Exception{
MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("j_username", "Sundar1234");
request.setParameter("j_password", "Sundar1234$$");
MockHttpServletResponse response = new MockHttpServletResponse();
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER");
List<SimpleGrantedAuthority> updatedAuthorities = new ArrayList<SimpleGrantedAuthority>();
updatedAuthorities.add(authority);
User user = new User("Sundar1234", "Sundar1234$$", updatedAuthorities);
Authentication auth = new UsernamePasswordAuthenticationToken(user,null);
EasyMock.expect(usernamePasswordAuthenticationFilter.attemptAuthentication(request, response)).andReturn(auth);
EasyMock.replay(usernamePasswordAuthenticationFilter);
Assert.assertNotNull(customAuthenticationFilter.attemptAuthentication(request, response));
EasyMock.verify(usernamePasswordAuthenticationFilter);
}
}
希望这可以解决您的问题。