I have integrated sygic in my android application using a surface view. I want to navigate in that sygic application . I have used this code :
SWayPoint wp = new SWayPoint();
wp.Location = new LONGPOSITION(34, 35);
ApplicationAPI.StartNavigation(err, wp, 0, true, false, MAX);
But it is not working. Any ideas ?
I have once implemented Sygic in an app and this is basically how my code looks like (after hours of debug because the documentation was very poor...):
// surfaceView for displaying the "map"
SurfaceView mSygicSurface = (SurfaceView) findViewById(R.id.sygic_surface); // surface
// api status
int mSygicAPIStatus = -2;
// start the drive
ApplicationAPI.startDrive(new ApiCallback() {
public void onRunDrive() {
mSygicSurface.post(new Runnable() {
public void run() {
runDrive(mSygicSurface, getPackageName());
}
});
}
public void onInitApi() // gets called after runDrive();
{
mSygicAPIStatus = ApplicationAPI.InitApi(getPackageName(), true, new ApplicationHandler() { /* nothing relevant here */ }); // api initialization
if (mSygicAPIStatus != 1) {
// error
return;
}
}
});
Once you want to navigate somewhere:
GeoPoint point = new GeoPoint(/* ... */, /* ... */);
final SWayPoint wayPoint = new SWayPoint("", point.getLongitudeE6(), point.getLatitudeE6());
SError error = new SError();
final int returnCode = ApplicationAPI.StartNavigation(error, point, NavigationParams.NpMessageAvoidTollRoadsUnable, true, true, 0);
Carefully note that Sygic uses E6 coordinates.
This is not an answer on the question, but for whose who searching for weird sygic exmaples in 2017 I put it here
ApiMaps.showCoordinatesOnMap(new Position((int)(-84.41949*100000.0),(int)(33.7455*100000.0)),1000,0);
//LONGITUDE first!!
//and multiply on 100 000
//https://developers.sygic.com/reference/java3d/html/classcom_1_1sygic_1_1sdk_1_1remoteapi_1_1_api_maps.html
p.s. this is for standalone apk
Related
I have been following the custom pin tutorial using Xamarin.Forms which I have linked below. I have finished implementing it and I have also moved onto adding pins to the map as well through tapping.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map/customized-pin
(side note: I am working almost exclusively with Xamarin.Forms and Android)
Currently, I am able to tap on the map and a new custom pin will be added at that location, which is great. What is not great is that I was unable to figure out how to get a tap and long hold gesture to work instead of just the normal tap. To try to combat this, and because I will eventually have to add these anyways, I am planning on adding a button that the user can press to initiate that they want to add a button to the map, and I will later add an undo button, and many others, etc.
The problem is, I have no idea how to get the result of what my toggle button state is from the custom render that I am using for the map. Where can I get the result of my toggle button and use it as a boolean towards whether to add a button or not?
Here is the toggle button code, which I took line by line from their example on this page:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/button
Here is the code where I add a custom pin just by a single tap:
private void GoogleMap_MapClick(object sender, GoogleMap.MapClickEventArgs e)
{
((CustomMap)Element).OnTap(new Position(e.Point.Latitude, e.Point.Longitude));
var addingPin = new CustomPin
{
Type = PinType.Place,
Position = new Position(e.Point.Latitude, e.Point.Longitude),
Address = " - need to possibly implement - ",
Id = "shelter",
Label = "Pin from tap",
Url = "http://www.redcross.org"
};
Map.Pins.Add(addingPin);
this.customPins.Add(addingPin);
}
I thought about making a custom button render but by my knowledge I can only apply one Android render to a content page at a time, and when I tried to add a custom button render to the map render then this method was not happy, as it was taking in some sort of Android Map View and not a button view:
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Map> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
NativeMap.InfoWindowClick -= OnInfoWindowClick;
}
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
customPins = formsMap.CustomPins;
Control.GetMapAsync(this);
}
}
Any help is greatly appreciated. Below I have included a pic of what my application looks like so far, along with the custom page that I am using as well.
using Hermes.Models;
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
namespace Hermes
{
public class MapPage : ContentPage
{
public MapPage()
{
CustomMap customMap = new CustomMap()
{
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand,
MapType = MapType.Street,
};
var examplePinSupplies = new CustomPin
{
Type = PinType.Place,
Position = new Position(42.02525, -93.65087),
Address = " - need to possibly implement - ",
Id = "supplies",
Label = "supplies",
Url = "https://www.redcross.org/store"
};
var examplePinMedical = new CustomPin
{
Type = PinType.Place,
Position = new Position(42.02290, -93.63912),
Address = " - need to possibly implement - ",
Id = "medical",
Label = "medical",
Url = "http://www.redcross.org"
};
var examplePinShelter = new CustomPin
{
Type = PinType.Place,
Position = new Position(42.02045, -93.60968),
Address = " - need to possibly implement - ",
Id = "shelter",
Label = "shelter",
Url = "http://www.redcross.org"
};
customMap.CustomPins = new List<CustomPin> { examplePinSupplies, examplePinMedical, examplePinShelter };
customMap.Pins.Add(examplePinSupplies);
customMap.Pins.Add(examplePinMedical);
customMap.Pins.Add(examplePinShelter);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(42.025250, -93.650870), Distance.FromMiles(1.0)));
var addPin = new ToggleButton { Text = "Add pin" };
var buttons = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Children = {
addPin
}
};
Content = new StackLayout
{
Spacing = 0,
Children = {
customMap,
buttons
}
};
}
}
}
What I am trying to do: I am trying to tap the 'add pin' toggle button, and then the map will allow me to only add one pin on the map by tapping, and then any other consecutive taps that are not on another pin will not add another pin to the map.
I've launched my new game libGDX on play store and I start getting crash reports.
This problem started when I updated to newer version on libgdx 1.9.7.
Here is my crash report:
java.lang.IllegalStateException:
at com.badlogic.gdx.graphics.glutils.GLFrameBuffer.build (GLFrameBuffer.java:233)
at com.badlogic.gdx.graphics.glutils.GLFrameBuffer.<init> (GLFrameBuffer.java:87)
at com.badlogic.gdx.graphics.glutils.FrameBuffer.<init> (FrameBuffer.java:51)
at com.badlogic.gdx.graphics.glutils.GLFrameBuffer$FrameBufferBuilder.build (GLFrameBuffer.java:474)
at com.dui.Screens.DirectedGame.setScreen (DirectedGame.java:57)
at com.dui.DuiGame.create (DuiGame.java:20)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged (AndroidGraphics.java:311)
at android.opengl.GLSurfaceView$GLThread.guardedRun (GLSurfaceView.java:1528)
at android.opengl.GLSurfaceView$GLThread.run (GLSurfaceView.java:1249)
Here is my setScreen method:
public void setScreen(AbstractGameScreen screen, ScreenTransition screenTransition) {
int w = Gdx.graphics.getWidth();
int h = Gdx.graphics.getHeight();
if (!init) {
GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(w, h);
frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGB8, GL30.GL_RGB, GL30.GL_UNSIGNED_BYTE);
currFbo = frameBufferBuilder.build();
nextFbo = frameBufferBuilder.build();
batch = new SpriteBatch();
init = true;
}
// start new transition
nextScreen = screen;
nextScreen.show(); // activate next screen
nextScreen.resize(w, h);
nextScreen.render(0); // let next screen update() once
if (currScreen != null) currScreen.pause();
nextScreen.pause();
Gdx.input.setInputProcessor(null); // disable input
this.screenTransition = screenTransition;
t = 0;
}
In libgdx news page there is example for building a custom FrameBuffer, but I'm not sure if I implement it correctly?
Can some one give me solution for my problem ?
Thanks
When getting the mission manager, either by DJIMissionManager.getInstance() or djiAircraftInstance.getMissionManager(), the mission manager instance is never connected, ie missionManagerInstance.isConnected() always returns false, and proceeding without the isConnected check causes a crash. Am I missing a step in setting up or retreiving the mission manager?
A minute ago I asked the same question on their forums here.
Any help would be appreciated. I have been over their examples a thousand times but it seems all of the examples are using an older version of the sdk.
EDIT: More information that you could figure out but I'll add in for the heck of it.
Mission manager instance is not null because calling isConnected() returns false, and the drone is connected as well.
I just test the isMissionReadyToExecute and MissionManager.isConnected, i found that no matter when I call them, they always return true. So I consider that it should be the bugs inside the SDK.
And I found a walk around solution for this problem.
Initialize the mission.
// Step 1: create mission
DJIWaypointMission waypointMission = new DJIWaypointMission();
waypointMission.maxFlightSpeed = 14;
waypointMission.autoFlightSpeed = 4;
List<DJIWaypoint> waypointsList = new LinkedList<>();
// Step 2: create waypoints and prepare coordinates
DJIWaypoint northPoint = new DJIWaypoint(mHomeLatitude + 10 * Utils.ONE_METER_OFFSET, mHomeLongitude, 10f);
DJIWaypoint eastPoint = new DJIWaypoint(mHomeLatitude, mHomeLongitude + 10 * Utils.calcLongitudeOffset(mHomeLatitude), 20f);
DJIWaypoint southPoint = new DJIWaypoint(mHomeLatitude - 10 * Utils.ONE_METER_OFFSET, mHomeLongitude, 30f);
DJIWaypoint westPoint = new DJIWaypoint(mHomeLatitude, mHomeLongitude - 10 * Utils.calcLongitudeOffset(mHomeLatitude), 40f);
//Step 3: add actions
northPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.GimbalPitch, -60));
northPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StartTakePhoto, 0));
eastPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StartTakePhoto, 0));
southPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.RotateAircraft, 60));
southPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StartRecord, 0));
westPoint.addAction(new DJIWaypoint.DJIWaypointAction(DJIWaypoint.DJIWaypointActionType.StopRecord, 0));
//Step 4: add waypoints into the mission
waypointsList.add(northPoint);
waypointsList.add(eastPoint);
waypointsList.add(southPoint);
waypointsList.add(westPoint);
waypointMission.addWaypoints(waypointsList);
mDJIMission = waypointMission;
prepare the mission.
mMissionManager.prepareMission(mDJIMission, new DJIMission.DJIMissionProgressHandler() {
#Override
public void onProgress(DJIMission.DJIProgressType type, float progress) {
setProgressBar((int)(progress * 100f));
}
}, new DJICompletionCallback() {
#Override
public void onResult(DJIError error) {
if (error == null) {
Utils.setResultToToast(mContext, "Success!");
} else {
Utils.setResultToToast(mContext, "Prepare: " + error.getDescription());
}
}
});
I work on project with yandexmapkit-android. Library link is https://github.com/yandexmobile/yandexmapkit-android
Documentation is very weak and github page is not fresh. Last update is 3 years ago.
I wanna draw route between two point but i can't find any function or method for this or example
Can you help me ?
As I can see, there are two ways to do it.
The first is calling Yandex Navigator as external application: https://github.com/yandexmobile/yandexmapkit-android/wiki/%D0%98%D0%BD%D1%82%D0%B5%D0%B3%D1%80%D0%B0%D1%86%D0%B8%D1%8F-%D1%81-%D0%9C%D0%BE%D0%B1%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D0%BC%D0%B8-%D0%AF%D0%BD%D0%B4%D0%B5%D0%BA%D1%81.%D0%9A%D0%B0%D1%80%D1%82%D0%B0%D0%BC%D0%B8
The second is using Yandex JS API with WebView: https://tech.yandex.ru/maps/doc/jsapi/2.0/ref/reference/route-docpage/
see yandex mapkit demo
mtRouter = MapKitFactory.getInstance().createMasstransitRouter();
mtRouter.requestRoutes(ROUTE_START_LOCATION, ROUTE_END_LOCATION,
new MasstransitOptions(new ArrayList<String>(), new ArrayList<String>(),
// Specify departure time or arrival time here
new TimeOptions()),
this);
// add points
List<RequestPoint> requestPoints = new ArrayList<>();
DrivingOptions drivingOptions = new DrivingOptions();
DrivingRouter drivingRouter = MapKitFactory.getInstance().createDrivingRouter();
DrivingSession drivingSession = drivingRouter.requestRoutes(
requestPoints, drivingOptions, new DrivingSession.DrivingRouteListener() {
#Override
public void onDrivingRoutes(List<DrivingRoute> routes) {
if (routes != null
&& !routes.isEmpty()) {
DrivingRoute route = routes.get(0);
BoundingBox box = BoundingBoxHelper.getBounds(route.getGeometry());
CameraPosition boundingBoxPosition = yandexMap.getMap()
.cameraPosition(box);
}
}
#Override
public void onDrivingRoutesError(Error error) {
//showErrorMessage }
});
You can easily use this method and set camera position
Hope it works for you
EDIT: I have a problem with SKMaps. I am trying to have a menu with buttons and display map with a calculated route underneath a button when the it is clicked. When I click it I download a gpx file and call the calculation of route with it to be performed. The first time I run the calculation it works (both calculates it and focuses on it). However every next time I call the function the route is indeed calculated but the focus is off by far.
My code is iOS but the same issue is present on android as well.
Myrouting delegate is set to self.
I remove the mapView before I add it as subview again.
The route is displayed just not focused on.
Relevant parts of my class are:
IOS:
- (void)viewDidLoad
{
[super viewDidLoad];
[self requestFiles];
fileData = [[NSMutableData alloc] init];
self.mapView = [[SKMapView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[SKRoutingService sharedInstance].mapView = self.mapView;
[SKRoutingService sharedInstance].routingDelegate = self;
}
-(void) generateContent{
self.container.contentSize = CGSizeMake(320, numberOfRoutes*65);
for (int i = 0; i<numberOfRoutes; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,i*50, 320, 55);
[button addTarget:self action:#selector(displayRoute:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:i+1];
[self.container addSubview:button];
}
}
-(void)displayRouteFile:(NSString *) fname{
if (downloadComplete) {
for (UIView *item in self.container.subviews) {
[item removeFromSuperview];
}
[self generateContent];
downloadComplete = NO;
self.mapView.frame = CGRectMake(0,(activeButtonNumber+1)*50+10, 320, 200);
self.container.contentSize = CGSizeMake(320, self.container.contentSize.height+210);
for (UIView *item in self.container.subviews) {
if ([item isKindOfClass:[UIButton class]]) {
UIButton *buttonToMove = (UIButton *) item;
if (buttonToMove.tag>activeButtonNumber+1) {
[buttonToMove setCenter:CGPointMake(item.center.x, item.center.y+220)];
}
}
}
[[SKRoutingService sharedInstance]clearCurrentRoutes];
[[SKRoutingService sharedInstance] clearAllRoutesFromCache];
[[SKRoutingService sharedInstance] clearRouteAlternatives];
[[SKRoutingService sharedInstance] startRouteFromGPXFile:fname];
[self.container addSubview:self.mapView];
}
}
-(IBAction)displayRoute:(UIButton *)sender{
UIButton *button = (UIButton *)sender;
[button setBackgroundImage:activeButtonBackground forState:UIControlStateNormal];
int route = button.tag-1;
activeButtonNumber = route;
receiveFile = YES;
//download route
...
fileData = [[NSMutableData alloc] init];
}
- (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation{
NSLog(#"Route is calculated with id: %u", routeInformation.routeID);
[routingService zoomToRouteWithInsets:UIEdgeInsetsZero];
// zoom to current route
^^^THIS PART DOES NOT WORK^^^
}
- (void)routingServiceDidFailRouteCalculation:(SKRoutingService *)routingService{
NSLog(#"Route calculation failed.");
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[SKRoutingService sharedInstance]clearCurrentRoutes];
activeButtonNumber = 0;
}
ANDROID:
I have an Activity called TestThis which I open multiple times (every time I supply it with a different filepath leading to a GPX file). The whole process works fine the first time I open the Activity - whatever filepath I supply it with it displays the route and then zooms on it. If I go back and select another filepath to create the activity with the new route is displayed but the map zooms somewhere else.
That is the order things happen:
onCreate I get the path to the file from the Bundle.
onSurfaceCreated I clear the currentRoute and start the calculation
of the new one.
onRouteCalculationCompleted I set the new route to be the current route.
onAllRoutesCompleted I try to zoom.
public class TestThis extends Activity implements SKRouteListener, SKMapSurfaceListener {
private static SKMapSurfaceView mapView;
String path;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prazen);
Bundle bundle = getIntent().getExtras();
path = bundle.getString("filepath");
RelativeLayout theArea = (RelativeLayout) findViewById(R.id.placeHere);
SKMapViewHolder myMapHolder = new SKMapViewHolder(TestThis.this);
mapView = myMapHolder.getMapSurfaceView();
mapView.setMapSurfaceListener(this);
mapView.getMapSettings().setCurrentPositionShown(false);
theArea.addView(myMapHolder);
SKRouteManager.getInstance().setRouteListener(TestThis.this);
}
#Override
public void onRouteCalculationCompleted(final int statusMessage, final int routeDistance, final int routeEta, final boolean thisRouteIsComplete, final int id) {
//SKRouteManager.getInstance().zoomToRoute((float)1.2, (float)1.2, 110, 8, 8, 8);
if(SKRouteManager.getInstance().setCurrentRouteByUniqueId(id)){
System.out.println("Current route selected!");
}
}
#Override
public void onAllRoutesCompleted() {
System.out.println("On all routes compl");
SKRouteManager.getInstance().zoomToRoute((float)1.2, (float)1.2, 110, 8, 8, 8);
//SKRouteManager.getInstance().zoomMapToCurrentRoute();
}
#Override
public void onSurfaceCreated() {
// TODO Auto-generated method stub
SKRouteManager.getInstance().clearCurrentRoute();
SKRouteManager.getInstance().setRouteFromGPXFile(path, SKRouteSettings.SKROUTE_CAR_SHORTEST, false, false, false);
}
}
IOS
The bug is on client side.
The problem is that when the route is calculated the previous frame of the map view is used and that's why the route is not centred. Moving
[self.container addSubview:self.mapView]; before the
[[SKRoutingService sharedInstance] clearCurrentRoutes];
[[SKRoutingService sharedInstance] clearAllRoutesFromCache];
[[SKRoutingService sharedInstance] clearRouteAlternatives];
[[SKRoutingService sharedInstance] startRouteFromGPXFile:fname];
should fix the problem.
Android:
The problem with incorrect zooming might occur when the call to zoomToRoute() is made soon after creating the activity. As a workaround for the issue the same approach as in the v2.2 open source demo may be followed: avoiding activity recreation and selecting the GPX tracks from the same activity as the one that displays the map - see the "Tracks" option in the demo's menu.
The original bug/cause will be addressed in a future update.