mapsplugin / cordova-plugin-googlemaps

Google Maps plugin for Cordova
Apache License 2.0
1.66k stars 914 forks source link

Using like DirectionsService #270

Closed Tong2203 closed 9 years ago

Tong2203 commented 9 years ago

In google map api, Route can be generated by DirectionsService. Could you tell how to do that in this plugin? thanks.

wf9a5m75 commented 9 years ago

This plugin does not provide the direction service currently. Many people want to use it, but not yet.

Tong2203 commented 9 years ago

OK, understand. By the way, does this plugin provide the compass mode?

wf9a5m75 commented 9 years ago

What is the compass mode?

Tong2203 commented 9 years ago

Like this... googlemaps_r-04

wf9a5m75 commented 9 years ago

Google Maps Android API v2 and Google Maps SDK for iOS provide the map compass. It appears when you change the map heading or set the camera heading.

Tong2203 commented 9 years ago

A direction that is always facing, I want to on the upper side of the screen.

wf9a5m75 commented 9 years ago

The plugin does not provide the feature.

Tong2203 commented 9 years ago

Ok I see,thank you.

wf9a5m75 commented 9 years ago

FYI: There is a compass plugin. https://github.com/apache/cordova-plugin-device-orientation

ghost commented 9 years ago

I think we can use google map api v3 javascript to calculate and get lines, and then draw into the map.

directionsService.route(
    directionsRequest,
    function (response, status) {
        //console.log('GOOGLE RESPONSE', response, status);
        if (status == google.maps.DirectionsStatus.OK) {

            var route = new Array(my_position);
            var steps = response.routes[0].legs[0].steps;
            //console.log('Steps:', steps)

            for (var s = 0; s < steps.length; s++) {
                for (var l = 0; l < steps[s]['lat_lngs'].length; l++) {
                    route.push(new plugin.google.maps.LatLng(steps[s]['lat_lngs'][l]['k'], steps[s]['lat_lngs'][l]['B']))
                }
            }

            //Draw Polyline
            if (oldPolyline) oldPolyline.remove();
                 map.addPolyline({
                    'points'    : route,
                    'color'     : '#3CABDA',
                    'width'     : 10,
                    'geodesic'  : true
                },
                function (polyline) {

                    //Keep reference of the last polyline used in order to remove it
                    // when a new route polyline is drawn
                    oldPolyline = polyline;

                    // Assign Event listener to polyline
                    // when user clicks the polyline he is transfered to the external
                    // navigation app
                    polyline.on(plugin.google.maps.event.OVERLAY_CLICK, function () {
                        plugin.google.maps.external.launchNavigation({
                            "from": my_position,
                            "to": position
                        });
                    });

                });
        }
        else
            console.error("Unable to retrieve route");
    }

);
sangariv commented 9 years ago

HI @aguilacontrol can u please tell explain this line var route = new Array(my_position);

wf9a5m75 commented 9 years ago

Before ask to someone, I recommend you search over the internet. http://www.w3schools.com/js/js_arrays.asp

sangariv commented 9 years ago

hi , i didnt ask about the array creation. i need to know what implies "my_position ".

wf9a5m75 commented 9 years ago

I think the value is just LatLng. You can get your position using map.getMyLocation()

sangariv commented 9 years ago

i got working..

iBasit commented 8 years ago

above one was not working for me, following will work fine.

var gRoute = response.routes[0]['overview_path'];
for (var s = 0; s < gRoute.length; s++) {
         route.push(new plugin.google.maps.LatLng(gRoute[s].lat(), gRoute[s].lng()));
 }

map.addPolyline({
                        points: route,
                        color : '#0088FF',
                        width: 6
                    });