<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nitin Yadav</title>
    <description>The latest articles on DEV Community by Nitin Yadav (@nitinyadav).</description>
    <link>https://dev.to/nitinyadav</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1062426%2F1757b6e4-7c2b-4ecc-ba3e-c97888127ffc.jpg</url>
      <title>DEV Community: Nitin Yadav</title>
      <link>https://dev.to/nitinyadav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nitinyadav"/>
    <language>en</language>
    <item>
      <title>Common Challenges of Benchmarking ETA Quality and How To Overcome Them</title>
      <dc:creator>Nitin Yadav</dc:creator>
      <pubDate>Mon, 19 Jun 2023 13:08:26 +0000</pubDate>
      <link>https://dev.to/nextbillion-ai/common-challenges-of-benchmarking-eta-quality-and-how-to-overcome-them-349m</link>
      <guid>https://dev.to/nextbillion-ai/common-challenges-of-benchmarking-eta-quality-and-how-to-overcome-them-349m</guid>
      <description>&lt;p&gt;The ability to provide accurate ETAs (Estimated Time of Arrival) is a crucial component of user experience across industries like ride hailing, field service, food delivery and logistics. Calculating ETAs using traditional methods (route planning + traffic information) and machine learning is very challenging; we won’t be covering that today. Instead, we will discuss one of the fundamentals of good ETAs — quantitatively measuring ETA quality. &lt;/p&gt;

&lt;p&gt;This blog was originally published &lt;a href="https://nextbillion.ai/blog/challenges-of-benchmarking-eta-quality-and-how-to-overcome"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Being a traditional estimation problem, there are already some well-known metrics that are designed for measuring ETA accuracy. When it comes to transportation in particular, there are more factors that need to be taken into account. In this article, we’ll begin by exploring the traditional metrics and then talk about our learnings around ETA benchmarking at NextBillion.ai.&lt;/p&gt;

&lt;h2&gt;
  
  
  Traditional statistical metrics
&lt;/h2&gt;

&lt;p&gt;Let’s look into some traditional estimation metrics that are widely used for ETA measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  MAPE: Mean Absolute Percentage Error
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M74XDAWP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjdnsx7pi4onw85eifhc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M74XDAWP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjdnsx7pi4onw85eifhc.png" alt="Image description" width="331" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;where At is the actual value and Et is the estimated value. A 10% MAPE means that if the Actual Time of Arrival (ATA) is 10 minutes, the original ETA was within the range of 9 – 11 minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros and Cons of MAPE
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; MAPE is a normalized number that is comparable among different types of trips and regions. You can directly compare your MAPE metrics in Paris against those in London. It’s also a rather straightforward concept; you can easily understand the meaning of a 10% MAPE.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; MAPE is too sensitive for short trips. Imagine a very quick trip that just takes a two-minute drive. The ETA for this trip could easily be anywhere from one to three minutes, but that leaves a MAPE of 50%. The impact of this 50% MAPE is equivalent to having a trip with an ETA of two hours that actually take three hours to complete.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A useful tip to use MAPE is to modify the formula to the following:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1LJvtTf9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c2stxd3xboic4t0cc54.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1LJvtTf9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c2stxd3xboic4t0cc54.png" alt="Image description" width="340" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ve changed the denominator from the actual value At to the estimated value Et. This makes things simpler from a user experience perspective, as users usually see the ETA first, and only when the trip finally ends do they compare the actual time taken against the original estimation. A modified MAPE of 10% means that if you start with an ETA of 10 minutes, the ATA will be within 9 – 11 minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  RMSE: Root-Mean-Square Error
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Tls9RUB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1a8jz53bixi1cjm28gx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Tls9RUB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1a8jz53bixi1cjm28gx.png" alt="Image description" width="318" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros and Cons of RMSE
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt; RMSE is dimensionally consistent, making it easy to understand. It essentially weights trips based on duration, instead of just error percentages, which circumvents the issues that MAPE faces with short trips.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Similar to how MAPE is sensitive to short trips, RMSE is sensitive to outliers in terms of trip duration; extreme outliers may lead to a poor value. Since RMSE is correlated to the duration of trips, it’s difficult to compare different regions with each other. A normalization needs to be applied.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both MAPE and RMSE are mathematical metrics that are great for complex calculations and can be used as objective functions in your machine learning algorithms. But can they measure how users feel about ETAs? It’s probably safe to say no. Nobody likes delayed trips, but people are much more tolerant of early arrivals. Also, the same margin of error could have differing impacts in different scenarios. For a short trip of 10 minutes, a 20% margin of error is just two minutes — some people may not even notice it. But in a 10-hour trip, a two-hour delay is hard to miss and can be intolerable. Clearly, these metrics can’t capture the whole picture. So let’s try to incorporate user experiences into our ETA measurements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design your own synthetic metrics for ETA experience
&lt;/h2&gt;

&lt;p&gt;ETAs can mean different things to different users across varying scenarios. Proper user research can tell you what would be a reasonable threshold before your user notices an ETA went wrong. Based on the research, we can build a ‘Good Estimation %’ metric like below:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ThPhcgpw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c36aqfj7rtyplujgdgrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ThPhcgpw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c36aqfj7rtyplujgdgrw.png" alt="Image description" width="646" height="103"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can define a good estimation as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For trips shorter than 24 hours, an error within the range of ±2 hours is considered a good estimation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For trips of 24 to 72 hours, an error of ±6 hours is considered a good estimation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For trips longer than 72 hours, an error of ±12 hours is considered a good estimation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can build even more user experience factors into this synthetic metric. For instance: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define thresholds based on urgency –&lt;/strong&gt; For all trips during peak hours (7am-10am and 5pm-8pm), errors within 20% are considered good estimations; for all trips during non-peak hours, errors within 40% are considered good estimations. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define thresholds based on customer type –&lt;/strong&gt; For trips involving VIP customers, errors within 10% are considered good estimations, whereas the threshold is 20% for all other trips.&lt;/p&gt;

&lt;p&gt;This Good Estimation % metric can be much better at showing what your users feel about their ETAs. &lt;/p&gt;

&lt;p&gt;On the other hand, you can look into user complaints and find out what a bad estimation looks like. A metric for Bad Estimation % can be introduced in addition to its more positive counterpart, and you can optimize your operations around these metrics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find insights from visualization
&lt;/h2&gt;

&lt;p&gt;All the metrics in the world are meaningless if you fail to draw any insights from them. Visualizations are extremely useful for doing just that. Let’s go over a few examples of drawing insights from data visualizations. &lt;/p&gt;

&lt;h2&gt;
  
  
  An ETA/Distance Error % Graph
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OlQJbTSR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1s2rzwjmziqa0e2w8mi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OlQJbTSR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1s2rzwjmziqa0e2w8mi9.png" alt="Image description" width="512" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This graph takes into account the distance factors of ETA. It helps us quickly understand if errors are caused by traffic or choice of route. In the above graph, we see an unusual group of samples where the distances are quite consistent, but the ETAs tend to be 200% off the actuals. Therefore, we can conclude that the errors are driven by traffic, and not route choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Box Plot Graph
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GZnGJBAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2o5giko8ywtcj7zmywoe.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GZnGJBAm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2o5giko8ywtcj7zmywoe.jpg" alt="Image description" width="512" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The box plot is a commonly used tool for visualizing the dispersion of data. It displays the minimum, first quartile, median, third quartile and maximum values of the data set. The whiskers extending from the boxes indicate the range of the data, while the individual points beyond the whiskers are outliers in the data. In the above figure, we can easily see that there’s a significant amount of deviation occurring within the 0-5 minute interval, which warrants a deeper look.&lt;/p&gt;

&lt;h2&gt;
  
  
  A 24-Hours ETA Graph
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JSXpEL20--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n42auiezdeesh0mgj74v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JSXpEL20--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n42auiezdeesh0mgj74v.png" alt="Image description" width="512" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a 24-hours graph comparing over-estimated (yellow) vs. good-estimation (green) vs. under-estimated (red) ETAs. By laying the data out in this manner, it becomes obvious that there is a traffic problem. The traffic data being used to generate ETAs in this scenario is probably the average data for each day, which is usually faster than peak-hour traffic and slower than non-peak-hour traffic. This explains the poorly estimated ETAs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grouping Trips
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---JGcMYTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z8tlt0yzj9a42b9rhtp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---JGcMYTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z8tlt0yzj9a42b9rhtp.png" alt="Image description" width="512" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This graph compares the errors of distance estimations with the actual distances. We see a significant group of longer trips showing a trend of underestimation, which is worth investigating. It could lead us to the underlying problem — perhaps a traffic issue, in this case. &lt;/p&gt;

&lt;p&gt;Sometimes it’s an art to group your data creatively in such a manner that the truth behind the data reveals itself. In transportation, some useful groupings include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Group by length of trips&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group by intra-city or intercity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group by morning-peak, noon, evening-peak, night and midnight&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group by weekday or weekend&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group by urban-region or country-region&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Group by vehicle types&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Combinations of the above&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can also be quite useful to look at week-on-week or month-on-month tracks.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SJGEDAA2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6bo0x9qtp0bx5klrpg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SJGEDAA2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6bo0x9qtp0bx5klrpg1.png" alt="Image description" width="512" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above image, we see ETA trends across different countries. Just from a glance, we can tell that in Country 2, traffic patterns became more unpredictable during the vacation season in July and August. &lt;/p&gt;

&lt;p&gt;All in all, it’s probably fair to say that benchmarking your ETAs is rarely going to be an easy or effortless process. However, it is your very first step towards generating high-quality ETAs, and thus, an extremely valuable exercise. We hope that this article will help you take that important step with purpose and confidence.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>ai</category>
    </item>
    <item>
      <title>The Ultimate Guide to Route Optimization: Boosting Efficiency and Reducing Costs</title>
      <dc:creator>Nitin Yadav</dc:creator>
      <pubDate>Mon, 12 Jun 2023 13:52:04 +0000</pubDate>
      <link>https://dev.to/nextbillion-ai/the-ultimate-guide-to-route-optimization-boosting-efficiency-and-reducing-costs-59o0</link>
      <guid>https://dev.to/nextbillion-ai/the-ultimate-guide-to-route-optimization-boosting-efficiency-and-reducing-costs-59o0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Vehicle route optimization is a process used by transportation and delivery-based businesses to plan and execute the most efficient and cost-effective routes for their vehicles. It involves using an API and algorithms to minimize travel time, reduce fuel consumption, and improve delivery efficiency. &lt;/p&gt;

&lt;p&gt;This blog was originally published &lt;a href="https://nextbillion.ai/blog/route-optimization-complete-guide-business"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This blog post will explore the critical components of vehicle route optimization, its definition, optimization process, and benefits. We will also explore how it is used by various businesses to streamline their operations and provide better service to their customers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is vehicle route optimization?
&lt;/h2&gt;

&lt;p&gt;Vehicle route optimization is crucial for transportation and delivery-based businesses. It uses API and algorithms to find the most efficient and cost-effective route for vehicles traveling from one location to another. &lt;/p&gt;

&lt;p&gt;This optimization process considers multiple factors such as distance, traffic, road conditions, and delivery schedules to generate the quickest and most fuel-efficient route. Vehicle route optimization aims to minimize travel time, reduce fuel consumption, and increase delivery efficiency.  &lt;/p&gt;

&lt;p&gt;Optimizing vehicle routes is crucial in today’s fast-paced business environment, where time is of the essence, and customers demand quick and efficient delivery. Vehicle route optimization helps transportation and delivery-based businesses streamline operations, reduce costs, and provide better customer service.  &lt;/p&gt;

&lt;p&gt;One of the critical benefits of vehicle route optimization is that it minimizes travel time and reduces fuel consumption. By using an API to calculate the quickest and most efficient route, delivery and transportation, companies can save time and increase cost savings.  &lt;/p&gt;

&lt;p&gt;Vehicle route optimization can be particularly important for delivery companies, which must make multiple deliveries daily, and for field services, which must make numerous visits to different locations. Another benefit of this optimization task is that it helps increase delivery efficiency.  &lt;/p&gt;

&lt;p&gt;Using a route optimization API to plan and execute the optimal route, delivery and transportation companies can ensure that their vehicles take the most efficient route, reducing the number of miles driven and increasing delivery speed. This leads to better customer satisfaction, as deliveries are made on time with fewer issues. &lt;/p&gt;

&lt;p&gt;Furthermore, vehicle route optimization can also help transportation and delivery-based businesses lower their carbon footprint by reducing fuel consumption.  &lt;/p&gt;

&lt;p&gt;Whether you’re a delivery company, courier service, or field service, vehicle route optimization is essential for optimizing your operations and taking your business to the next level.  &lt;/p&gt;

&lt;p&gt;The technology can help the transportation and delivery-based businesses plan and execute the most efficient and cost-effective routes for their vehicles, reducing travel time, fuel consumption, and costs while improving customer satisfaction and increasing efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges faced when manually generating an optimal route
&lt;/h2&gt;

&lt;p&gt;When manually generating an optimal route, the challenges become even more pronounced as the scale of operations increases. Here are some reasons why manually generating an optimal route can be challenging.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time-consuming:&lt;/strong&gt; Manually plotting the routes, considering all the factors, such as traffic, road conditions, and delivery schedules, can take a lot of time and effort. This can lead to inefficiencies and slowdowns in the delivery process.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inconsistent results:&lt;/strong&gt; Plotting routes manually takes time to achieve consistent results. Human error, such as misinterpreting maps or overlooking important information, can lead to incorrect route planning. This can lead to delays and higher fuel usage.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lack of real-time updates:&lt;/strong&gt; While manual route planning, accounting for real-time updates such as traffic changes or road closures can be difficult. This can lead vehicles to take longer routes, incur additional fuel costs, and ultimately impact delivery times.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; As the number of vehicles and deliveries grows, manually planning routes becomes more and more complex, making it hard to ensure consistent and efficient results.&lt;/p&gt;

&lt;p&gt;The benefits of vehicle route optimization are not limited to on-demand delivery companies but extend to various industries such as field services, fleet management, and more.  &lt;/p&gt;

&lt;p&gt;By automating the route optimization process, companies can save time, reduce costs, and improve the overall efficiency of their operations. For instance, consider a field services company that needs to send technicians to various locations to perform maintenance and repair work.  &lt;/p&gt;

&lt;p&gt;Manual route planning makes it challenging to allocate technicians efficiently while considering real-time updates and multiple factors like traffic, road conditions, and appointment schedules. Manual route optimization can lead to longer response times, increased fuel consumption, and higher costs.  &lt;/p&gt;

&lt;p&gt;A company can promptly determine the most cost-effective and efficient route while factoring in all relevant considerations using vehicle route optimization API. This leads to faster and more efficient service, facilitating a company’s ability to scale operations and meet the surging demand for its services. &lt;/p&gt;

&lt;p&gt;Also Read – &lt;a href="https://nextbillion.ai/blog/end-to-end-delivery-route-optimization"&gt;End-to-End Route Optimization API: Vehicle Routing Problem Solver for Mobility-Driven Businesses&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How vehicle route optimization helps in the following –
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Last Mile Delivery
&lt;/h2&gt;

&lt;p&gt;Last-mile delivery can be one of the most complex and time-consuming tasks for a delivery-based business. With the rise of e-commerce and the increasing demand for home delivery, companies face new challenges regarding last-mile delivery.&lt;/p&gt;

&lt;p&gt;However, with the help of vehicle route optimization solutions, businesses can streamline their last-mile delivery operations, reduce delivery times, and provide better service to their customers. &lt;/p&gt;

&lt;p&gt;One of the critical benefits of vehicle route optimization for last-mile delivery is reducing travel time. By considering real-time traffic and road conditions, an optimization API can generate the quickest route, helping delivery vehicles to reach their destination faster.  &lt;/p&gt;

&lt;p&gt;Route optimization API not only reduces delivery time but also helps to reduce fuel consumption, making last-mile delivery more efficient and cost-effective. &lt;/p&gt;

&lt;p&gt;Another advantage of vehicle route optimization for last-mile delivery is improving delivery accuracy. By taking into account delivery schedules, appointment windows, and other scheduling constraints, the API can ensure that deliveries are made on time, improving operational efficiency and reducing the risk of missed deliveries. &lt;/p&gt;

&lt;p&gt;For businesses that deal with large-scale, on-demand deliveries, vehicle route optimization is essential for scalability. Manually planning routes for many deliveries can be time-consuming and prone to errors. Vehicle route optimization APIs can quickly generate efficient and cost-effective routes for large-scale deliveries, making the process faster and more accurate. &lt;/p&gt;

&lt;p&gt;NextBillion.ai’s Route Optimization API is a powerful tool that helps businesses optimize their last-mile delivery operations. The API uses machine learning algorithms and real-time data to determine the most efficient and cost-effective route for a delivery vehicle. By considering factors such as distance, traffic, road conditions, and delivery schedules, the API can generate the quickest and most fuel-efficient route for last-mile delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  On-demand delivery
&lt;/h2&gt;

&lt;p&gt;On-demand delivery businesses face several challenges in optimizing their routes, including manual planning, real-time traffic, road conditions, delivery schedules, and scalability. NextBillion.ai’s Route Optimization API addresses these challenges and provides a fast, efficient, and cost-effective solution.  &lt;/p&gt;

&lt;p&gt;The API uses vital parameters such as distance, traffic, road conditions, delivery schedules, and scalability to optimize on-demand delivery routes. It calculates the shortest distance between two points by taking into account the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-time traffic data and road conditions to avoid congestion &lt;/li&gt;
&lt;li&gt;Road closures and other obstacles to find alternative routes&lt;/li&gt;
&lt;li&gt;Delivery deadlines and other scheduling constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By implementing NextBillion.ai’s Route Optimization API, businesses can save up to 30% on delivery costs and reduce delivery time by up to 20%, resulting in improved customer satisfaction and increased profits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fleet management
&lt;/h2&gt;

&lt;p&gt;Vehicle route optimization helps fleet managers determine the most efficient and cost-effective routes for their vehicles, improving operational efficiency, reducing fuel consumption, and boosting profits. &lt;/p&gt;

&lt;p&gt;NextBillion.ai’s Route Optimization API is designed to help fleet managers optimize their routes. The solution uses a variety of parameters to generate the most efficient routes, including&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Distance:&lt;/strong&gt; The solution calculates the shortest distance between two points, taking into account real-time traffic and road conditions to reduce travel time and fuel consumption.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traffic:&lt;/strong&gt; Real-time traffic data is used to avoid congestion and find alternative routes when necessary, helping to reduce travel time and fuel consumption.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Road Conditions:&lt;/strong&gt; The solution takes into account road closures, construction zones, and other obstacles that could slow down delivery, allowing fleet managers to find alternative routes and avoid any potential delays.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Delivery Schedules:&lt;/strong&gt; The solution considers delivery deadlines, appointment windows, and other scheduling constraints to ensure that deliveries are made on time, improving operational efficiency and providing customer service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Load Capacity:&lt;/strong&gt; The solution considers each vehicle’s load capacity, ensuring that the most efficient route is chosen for each vehicle and maximizing the use of each vehicle’s capacity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By considering all of these factors, NextBillion.ai’s Route Optimization API generates the quickest and most fuel-efficient route, helping fleet managers streamline their operations and improve their bottom line. Businesses that use NextBillion.ai’s map data solutions have seen an average increase in profits of 15% within the first year.&lt;/p&gt;

&lt;h2&gt;
  
  
  Field service
&lt;/h2&gt;

&lt;p&gt;Route optimization API can help field services companies to streamline their operations and improve their bottom line. With advanced algorithms and real-time data analysis, these APIs can help companies optimize their delivery routes, reduce fuel consumption, and improve customer satisfaction. &lt;/p&gt;

&lt;p&gt;Here are some of the critical benefits that field services companies can realize by using route optimization API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Efficient ETA management:&lt;/strong&gt; By taking into account real-time traffic conditions and other factors, route optimization API can help companies estimate more accurate delivery times. This helps companies meet customer expectations and reduce the number of missed or late deliveries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient dispatch management:&lt;/strong&gt; Route optimization API can help companies plan their delivery routes in the most efficient way possible, taking into account multiple factors such as delivery schedules, road conditions, and traffic. With this API, companies can reduce the time it takes to dispatch deliveries and minimize the number of miles traveled, reducing fuel consumption and improving delivery times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asset lives tracking:&lt;/strong&gt; Many route optimization APIs also comes with live tracking features that allow companies to keep track of their vehicles and delivery drivers in real time. With this information, companies can monitor the progress of deliveries, ensure that drivers are following the optimal routes, and take action to resolve any issues that may arise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mileage-based reimbursement:&lt;/strong&gt; Route optimization API can help companies calculate the mileage that their vehicles travel on each delivery, making it easier to process reimbursement claims for drivers. By accurately tracking the miles traveled, companies can reduce the time it takes to process these claims and minimize the risk of errors or discrepancies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also Read – &lt;a href="https://nextbillion.ai/blog/custom-map-solutions-for-field-services"&gt;Empower the Next Generation of Field Agents with Custom Map Solutions for Field Services&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;By using a route optimization API, field services companies can improve efficiency, reduce costs, and provide better customer service. The right API can help companies to optimize their delivery routes, minimize travel time, reduce fuel consumption, and increase delivery efficiency, ultimately leading to increased profitability and growth. &lt;/p&gt;

&lt;p&gt;For these reasons, companies looking to streamline their operations and improve their bottom line should consider implementing a route optimization API like NextBillion.ai. With advanced algorithms, real-time data analysis, and user-friendly features, NextBillion.ai can help companies achieve their operational and financial goals, providing a powerful and effective solution for their delivery operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why your business needs route optimization APIs
&lt;/h2&gt;

&lt;p&gt;Route optimization is an essential component of modern logistics and delivery operations. It helps companies to optimize their routes, reduce fuel consumption, and improve operational efficiency, resulting in significant cost savings and increased profits. In today’s fast-paced and highly competitive business environment, route optimization is no longer a luxury but a critical requirement for companies looking to stay ahead of the curve. &lt;/p&gt;

&lt;p&gt;For businesses, building a robust and sophisticated route optimization solution in-house can be a time-consuming and expensive process. It requires a significant resource investment, including software development, data collection and analysis, and infrastructure. Furthermore, it’s also challenging to keep pace with the constantly evolving market demands and technological advancements. &lt;/p&gt;

&lt;p&gt;NextBillion.ai’s Route Optimization API provides a cost-effective and efficient solution for companies looking to optimize their routes. The API uses a variety of parameters to generate the most efficient ways, including distance, traffic, road conditions, delivery schedules, and load capacity. It leverages real-time data and advanced algorithms to provide businesses with the most up-to-date and accurate information, allowing them to make informed decisions and achieve their operational goals. &lt;/p&gt;

&lt;p&gt;The API is designed to integrate easily with existing systems, providing companies with a seamless and streamlined solution. Businesses can optimize routes for various use cases, including fleet management, field services, on-demand delivery, and last-mile delivery. With NextBillion.ai, companies can focus on their core business while leaving complex routing and optimization tasks to the experts. &lt;/p&gt;

&lt;p&gt;In addition to the time and cost savings, using NextBillion.ai’s Route Optimization API positively impacts a company’s bottom line. By optimizing routes, companies can reduce fuel consumption, improve delivery times, and enhance customer satisfaction. This leads to increased profits and a more competitive edge in the marketplace.&lt;/p&gt;

&lt;h2&gt;
  
  
  10 things to look for in route optimization API
&lt;/h2&gt;

&lt;p&gt;When considering route optimization API for your business, it is essential to consider several factors to ensure that the solution meets your needs and delivers the desired results. The following are some of the critical elements that you should look for in a route optimization solution:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Essential Features:&lt;/strong&gt;&lt;br&gt;
Ensure that the API has the necessary features to meet your requirements. Some of the crucial elements to look for include route optimization, real-time traffic updates, real-time vehicle tracking, and delivery schedule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Number of Parameters:&lt;/strong&gt;&lt;br&gt;
A good route optimization API should consider various parameters to generate the most efficient routes. The more parameters considered, the more accurate and effective the solution. Ensure that it can account for traffic, road conditions, delivery schedules, and load capacity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost:&lt;/strong&gt; Consider the cost, including both the initial cost and the ongoing costs, such as support and maintenance. Look for a solution that offers a competitive price without compromising quality and features.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; Ensure that it is scalable and can grow with your business. A scalable solution will allow you to add more vehicles, routes, and deliveries without needing additional hardware or software.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User-Friendly Interface:&lt;/strong&gt; Ensure that it is easy to use and has a user-friendly interface. The solution should be intuitive so that even non-technical users can quickly get started with the API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration:&lt;/strong&gt; Ensure that it smoothly integrates with other systems used by your business, such as customer relationship management (CRM) and enterprise resource planning (ERP) systems.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; Ensure that it is reliable and that it operates 24/7. A reliable solution will ensure that you can rely on it to make critical decisions, even in challenging conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Technical Support:&lt;/strong&gt; Look for an API that offers comprehensive technical support, including online resources, email support, and telephone support. This will ensure that you can get help when you need it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customer Feedback:&lt;/strong&gt; Opt for an API that other customers have reviewed and recommended. Read online reviews and customer feedback on trusted sites to better understand the solution and its capabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ROI:&lt;/strong&gt; Consider its return on investment (ROI). Look for a solution that provides a quick and measurable return on investment so that you can see a positive impact on your business as soon as possible.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Check NextBillion.ai – &lt;a href="https://nextbillion.ai/route-optimization-api"&gt;Route Optimization API &lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In conclusion, when looking for a route optimization API, it is essential to consider a range of factors, including important features, number of parameters supported, cost, scalability, user-friendly interface, integration, reliability, technical support, customer feedback, and return on investment. &lt;/p&gt;

&lt;p&gt;Considering these factors, you can ensure that you choose a solution that meets your needs and delivers the desired results. NextBillion.ai’s Route Optimization API is extremely feature-rich, including a built-in custom map stack, the ability to account for real-time traffic updates, the ability to solve an array of routing problems with multiple constraints, and more. &lt;/p&gt;

&lt;p&gt;Additionally, the solution offers a scalable platform, a user-friendly interface, and comprehensive technical support, making it an excellent choice for businesses of all sizes.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>api</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to build a Swiggy like tracking experience with NextBillion.ai in VueJS</title>
      <dc:creator>Nitin Yadav</dc:creator>
      <pubDate>Thu, 08 Jun 2023 13:35:38 +0000</pubDate>
      <link>https://dev.to/nextbillion-ai/how-to-build-a-swiggy-like-tracking-experience-with-nextbillionai-in-vuejs-44i9</link>
      <guid>https://dev.to/nextbillion-ai/how-to-build-a-swiggy-like-tracking-experience-with-nextbillionai-in-vuejs-44i9</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;For products involving deliveries, ride-hailing, ecommerce, and logistics, it is important include an optimized last-mile delivery tracking experience. NextBillion.ai provides a set of mapping and location-based service APIs and SDKs that allow developers to easily integrate maps and last mile tracking into the product.&lt;/p&gt;

&lt;p&gt;This blog was orginally published &lt;a href="https://nextbillion.ai/blog/how-to-build-swiggy-like-app"&gt;HERE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we will go through the steps to create a Swiggy like last mile delivery tracking experience with the NextBillion API and SDK using VueJS. &lt;/p&gt;

&lt;p&gt;By the end of this tutorial you should be able to;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a Map using NextBillion SDK in VueJS&lt;/li&gt;
&lt;li&gt;Add custom Markers on the NextBillion Map&lt;/li&gt;
&lt;li&gt;Get location address and discover locations using NextBillion API&lt;/li&gt;
&lt;li&gt;Use NextBillion &lt;a href="https://docs.nextbillion.ai/docs/navigation/api/directions"&gt;Directions API&lt;/a&gt; to get and render directions for live order tracking.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;To follow this tutorial you must have&lt;/p&gt;

&lt;p&gt;Basic understanding on Vue. &lt;a href="https://vuejs.org/guide/introduction.html"&gt;VueJs Docs&lt;/a&gt; are a great place to start learning Vue.&lt;br&gt;
NextBillion API host url and API key. Create a NextBillion account by visiting the &lt;a href="https://doc.maps.nextbillion.io/docs/get-an-api-key"&gt;Get API key page&lt;/a&gt; in NextBillion docs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Now that we have NextBillion API host and API key, let us setup our Vue project with NextBillion SDK. &lt;/p&gt;

&lt;p&gt;I’ll assume that as a foundation you have node.js installed on your system and you will use the node package manager (npm) to install the Vue CLI globally.&lt;br&gt;
$ npm install -g vue&lt;/p&gt;

&lt;p&gt;Create the default boilerplate project using Vue CLI in a directory where you want to manage your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. npm init vue@latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be prompted to add a project name and some project settings. Select the options as per your requirements. I will use nbai as my project name. After the project is created, change directory to the project, install dependencies and start the dev server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. npm install
2. npm run dev

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt; from your browser and you should be able to see the default Vue application running. &lt;/p&gt;

&lt;p&gt;Let us now add NextBillion SDK and some other dependencies to our project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. # NextBillion SDK
2. npm install nbmap-gl
3. 
4. # TailwindCSS for styling.
5. npm install -D tailwindcss postcss autoprefixer
6. 
7. # Fontawesome icons for map markers
8. npm i --save @fortawesome/fontawesome-svg-core
9. npm i --save @fortawesome/free-solid-svg-icons
10. npm i --save @fortawesome/free-regular-svg-icons
11. npm i --save @fortawesome/free-brands-svg-icons

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: See &lt;a href="https://tailwindcss.com/docs/installation/using-postcss"&gt;TailwindCSS docs&lt;/a&gt; and &lt;a href="https://fontawesome.com/docs/web/use-with/vue/"&gt;FontAwesome docs&lt;/a&gt; for their respective setup documentation. You can use alternative styling and icon options as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding NextBillion SDK
&lt;/h2&gt;

&lt;p&gt;Create a .env file with VITE_NEXTBILLION_API_KEY and VITE_NEXTBILLION_API_HOST values. &lt;/p&gt;

&lt;p&gt;Now modify src/main.js file to integrate the NextBillion SDK.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. javascript
2. import nextbillion from 'nbmap-gl'
3. nextbillion.setApiKey(import.meta.env.VITE_NEXTBILLION_API_KEY)
4. nextbillion.setApiHost(import.process.env.VITE_NEXTBILLION_API_HOST)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that our basic setup is complete, let’s start building.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Map Component
&lt;/h2&gt;

&lt;p&gt;We will create a Vue Component (NBapiMAP) for our Map which will be responsible for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rendering the map using NextBillion SDK.&lt;/li&gt;
&lt;li&gt;Given a geo-location, render Marker on the map.&lt;/li&gt;
&lt;li&gt;Given origin and destination, render directions for order tracking.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Displaying the Map
&lt;/h2&gt;

&lt;p&gt;Lets start with simple component which renders the map using NextBillion SDK when mounted to the DOM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;template&amp;gt;
2. &amp;lt;div class="map-container" id="map"&amp;gt;&amp;lt;/div&amp;gt;
3. &amp;lt;/template&amp;gt;
4. &amp;lt;script&amp;gt;
5. import nextbillion from "nbmap-gl";
6. import { decodePolyline } from "nbmap-gl/src/maps/decoder";
7. export default {
8. name: "NBaiMap",
9. props: {
10. center: {
11.     lat: 28.6139,
12.     lng: 77.209,
13. },
14. zoom: Number,
15. }
16. data() {
17. return {
18.     map: null
19. }
20. },
21. methods: {
22.     mapClicked: function(event) {
23.     this.$emit("update-location", event.lngLat);
24. },
25. _renderMap: function () {
26.     this.map = new nextbillion.maps.Map(document.getElementById("map"), {
27.     zoom: this.zoom || 12,
28.     center: this.center,
29. });
30. }
31.     this.map.on("click", this.mapClicked)
32. },
33. mounted() {
34.     this._renderMap();
35. }
36. }
37. &amp;lt;/script&amp;gt; &amp;lt;style lang="postcss" scoped&amp;gt;
38. /* The map container will expand to its parent's height and width*/
39. .map-container {
40. @apply w-full min-h-full;
41. }
42. &amp;lt;/style&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This component takes two props center and zoom for rendering the map. Notice that we have added a click event handler to the map. The component will emit a custom event update-location with LatLng whenever the map is click. We can use this to set user or store locations. &lt;/p&gt;

&lt;p&gt;Lets use the NBaiMap in another component to render the Map. Create a file src/views/MapPage.vue and add following content to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;template&amp;gt;
2. &amp;lt;div class="h-screen flex flex-col flex-1"&amp;gt;
3. &amp;lt;div class="h-full flex flex-1 flex-grow"&amp;gt;
4. &amp;lt;NBaiMap ref="map" v-if="haveLocation" :center="userLocation"&amp;gt;&amp;lt;/NBaiMap&amp;gt;
5. &amp;lt;/div&amp;gt;
6. &amp;lt;/div&amp;gt;
7. &amp;lt;/template&amp;gt;
8. &amp;lt;script&amp;gt;
9. import NBaiMap from "@/components/NBaiMap.vue";
10. export default {
11. name: "MapPage",
12. components: {
13. NbaiMap,
14. },
15. data() {
16. return {
17. haveLocation: false,
18. userLocation: {
19.     lat: null,
20.     lng: null,
21. },
22. };
23. },
24. methods: {
25. geolocationSuccess: function (geolocation) {
26.     this.haveLocation = true;
27.     const { latitude, longitude } = geolocation.coords;
28.     this.userLocation.lat = latitude;
29.     this.userLocation.lng = longitude;
30. },
31. },
32. mounted() {
33.     if (window.navigator.geolocation) {
34.     window.navigator.geolocation.getCurrentPosition(this.geolocationSuccess);
35. }
36. },
37. };

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This page gets user location from window.navigator.geolocation.getCurrentPosition browser API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WTVkIKpa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yg6wa01yl847uhctpyko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WTVkIKpa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yg6wa01yl847uhctpyko.png" alt="Image description" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Markers to the Map
&lt;/h2&gt;

&lt;p&gt;Let us now add a method to render Marker with custom font-awesome icon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. ...
2. methods: {
3. // ...
4. _renderMarker: function (postion, icon) {
5. const marker = new nextbillion.maps.Marker({
6. position: position,
7. map: this.map,
8. });
9. // Change the icon if provided
10. if (icon !== null){
11. const markerElement = marker.getElement();
12. markerElement.style.backgroundImage = null;
13. markerElement.innerHTML = ``;
14. }
15. return marker;
16. },
17. // ...
18. }
19. ...

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method _renderMarker takes position (Object with lat and lng keys) and icon (font-awesome icon class) and renders the icon on given position. &lt;/p&gt;

&lt;p&gt;Lets render default Markers on map click by listenting to update-location event from NBaiMap,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;template&amp;gt;
2. ...
3. &amp;lt;NBaiMap @update-location="renderMarker"&amp;gt;&amp;lt;/NBaiMap&amp;gt;
4. ...
5. &amp;lt;/template&amp;gt;
6. &amp;lt;script&amp;gt;
7. //...
8. methods: {
9. renderMarker: function (event) {
10. this.$refs.map._renderMarker({lat: event.lat, lng: event.lng})
11. }
12. }
13. //...
14. &amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now click on the map and a marker should be rendered where you clicked.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pfjcASLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjvulh9hqr6ownd4dy6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pfjcASLQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjvulh9hqr6ownd4dy6o.png" alt="Image description" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also render custom Markers by passing _renderMarker with font-awesome icon class as secondary argument. For example, let’s add multiple stores with fa-store icon.&lt;br&gt;
this.$refs.map._renderMarker({lat: event.lat, lng: event.lng}, 'fa-store') &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mN-KRAle--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scg3cjif813gq5oai86x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mN-KRAle--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scg3cjif813gq5oai86x.png" alt="Image description" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Fetching and displaying Directions
&lt;/h2&gt;

&lt;p&gt;Add a method to render Directions given origin and destination coordinates. We will add a Polyline for route as we can use it to modify the strokeColor and strokeWidth of the route.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;script&amp;gt;
2. import { decodePolyline } from "nbmap-gl/src/maps/decoder";
3. //...
4. data() {
5. // ...
6. origin: null,
7. destination: null,
8. originMarker: null,
9. destinationMarker: null,
10. deliveryExecutiveMarker: null,
11. // ...
12. },
13. methods: {
14. _fitBounds: function (bounds, options) {
15. if (!options) {
16. options = {};
17. }
18. options.padding = 100;
19. this.map.map.fitBounds(bounds, options);
20. },
21. renderDirections: async function (origin, destination) {
22. const directions = await nextbillion.api.Directions({
23. origin,
24. destination,
25. steps: true,
26. });
27. const coords = decodePolyline(directions.routes[0].geometry, 5);
28. const path = [coords.map((item) =&amp;gt; ({ lat: item[0], lng: item[1] }))];
29. new nextbillion.maps.Polyline({
30. path: path,
31. strokeWeight: 5,
32. map: this.map,
33. });
34. this.originMarker = this._renderMarker(origin);
35. this.destinationMarker = this._renderMarker(destination)
36. this._fitBounds([origin, destination], {});
37. this.origin = origin;
38. this.destination = destination;
39. this.$emit("update-path-duration", directions.routes[0].duration);
40. }
41. }
42. &amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zWTJayym--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekby6f82yf3vvwfcdl19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zWTJayym--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekby6f82yf3vvwfcdl19.png" alt="Image description" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s add some helper methods to our NBaiMap to add and remove custom origin, destination and live tracking Markers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. methods: {
2. // ...
3. _addOriginMarker: function (loc) {
4. if (this.originMarker === null) {
5. this.originMarker = this._renderMarker(loc, "fa-store");
6. }
7. },
8. _removeOriginMarker: function () {
9. if (this.originmarker !== null) {
10. this.originMarker.remove();
11. this.originMarker = null;
12. }
13. },
14. _addDestinationMarker: function (loc) {
15. if (this.destinationMarker === null) {
16. this.destinationmarker = this._renderMarker(loc, "fa-location-dot");
17. }
18. },
19. _removeDestinationMarker: function () {
20. if (this.destinationMarker !== null) {
21. this.destinationMarker.remove();
22. this.destinationMarker = null;
23. }
24. },
25. _addDeliveryMarker: function (loc) {
26. if (this.deliveryExecutiveMarker === null) {
27. this.deliveryExecutiveMarker = this._renderMarker(loc, "fa-moped");
28. }
29. },
30. _removeDeliveryMarker: function () {
31. if (this.deliveryExecutiveMarker !== null) {
32. this.deliveryExecutiveMarker.remove();
33. this.deliveryExecutiveMarker = null;
34. }
35. },
36. // ...
37. }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also change the route color by passing strokeColor: "#f59e0b" to nextbillion.maps.Polyline. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8AVjHzV_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/304p7tc1qgb4gr1xilet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8AVjHzV_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/304p7tc1qgb4gr1xilet.png" alt="Image description" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add methods to move a marker. This will be used to move the live location marker and update the estimated delivery time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. methods: {
2.  // ...
3.  _moveMarker: function (markerRef, loc) {
4.  if (markerRef !== null) {
5.  markerRef.moveTo(loc);
6.  }
7.  },
8.  updateLiveLocation: function(loc) {
9.  this._moveMarker(this.deliveryExecutiveMarker, loc);
10.     const directions = await nextbillion.api.Directions({
11.     origin: loc,
12.     destination: this.destination,
13.     })
14.     this.$emit("update-path-duration", directions.routes[0].duration)
15.     }
16.     // ...
17.     }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see the complete component at github link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting User and Store Location
&lt;/h2&gt;

&lt;p&gt;Let us now use our NBaiMap component and create SetAddress component to get user and store location. I will use localStorage to save these locations. You would want to store these locations to your database using a backend server. &lt;/p&gt;

&lt;p&gt;Add basic template and methods. Styles are removed for brevity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;template&amp;gt;
2. &amp;lt;div class="h-screen flex flex-1 flex-col"&amp;gt;
3. &amp;lt;div class="header"&amp;gt;Set {{ addressKey }} Address&amp;lt;/div&amp;gt;
4. &amp;lt;div class="address-controls-container"&amp;gt;
5. &amp;lt;div v-if="!addressSet" class="search-container"&amp;gt;
6. &amp;lt;div class="input z-index-50"&amp;gt;
7. &amp;lt;input id="searchbox" class="input-box" v-model="q" /&amp;gt;
8. &amp;lt;div class="suggestion-container" v-show="showSuggestions"&amp;gt;
9. &amp;lt;div class="suggestion"&amp;gt;
10. &amp;lt;div v-for="place in suggestions" :key="place" @click="flyToLocation(place)"&amp;gt;{{ place.address.label }}&amp;lt;/div&amp;gt;
11. &amp;lt;/div&amp;gt;
12. &amp;lt;/div&amp;gt;
13. &amp;lt;/div&amp;gt;
14. &amp;lt;button class="search-btn" @click="discover"&amp;gt;Search&amp;lt;/button&amp;gt;
15. &amp;lt;/div&amp;gt;
16. &amp;lt;div v-else class="flex my-auto"&amp;gt;
17. &amp;lt;div class="selected-address"&amp;gt;{{ address.address.label }}&amp;lt;/div&amp;gt;
18. &amp;lt;button class="btn" @click="confirmLocation"&amp;gt;Confirm&amp;lt;/button&amp;gt;
19. &amp;lt;button class="btn" @click="resetLocation"&amp;gt;Change&amp;lt;/button&amp;gt;
20. &amp;lt;/div&amp;gt;
21. &amp;lt;/div&amp;gt;
22. &amp;lt;div class=""&amp;gt;
23. &amp;lt;NBaiMap @update-location="setNewAddress" ref="map" :center="userLocation" :zoom="14"&amp;gt;&amp;lt;/NBaiMap&amp;gt;
24. &amp;lt;/div&amp;gt;
25. &amp;lt;/div&amp;gt;
26. &amp;lt;/template&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. &amp;lt;script&amp;gt;
2. import NBaiMap from "@/components/NbaiMap.vue";
3. export default {
4. name: "SetAddress",
5. components: {
6. NbaiMap,
7. },
8. props: {
9. addressKey: {
10. type: String,
11. default: "Home",
12. },
13. },
14. data() {
15. return {
16. q: "",
17. userLocation: {
18. lat: null,
19. lng: null
20. }
21. }
22. },
23. methods: {
24. confirmLocation: function () {
25. localStorage.removeItem(this.addressKey);
26. localStorage.setItem(this.addressKey, JSON.stringify(this.address));
27. this.$emit("address-set");
28. },
29. resetLocation: function () {
30. if (this.marker) {
31. this.marker.remove();
32. }
33. this.addressSet = false;
34. this.address = null;
35. },
36. renderMarker: function (loc) {
37. if (this.marker) {
38. this.marker.remove();
39. }
40. this.marker = this.$refs.map.renderMarker(loc);
41. },
42. geolocationSuccess: function (geolocation) {
43. const { latitude, longitude } = geolocation.coords;
44. this.userLocation.lat = latitude;
45. this.userLocation.lng = longitude;
46. },
47. flyToLocation: function (place) {
48. this.address = place;
49. this.addressSet = true;
50. this.showSuggestions = false;
51. this.$refs.map.map.flyTo({
52. center: place.position,
53. zoom: 14,
54. });
55. this.renderMarker(place.position);
56. },
57. },
58. mounted() {
59. if (window.navigator.geolocation) {
60. window.navigator.geolocation.getCurrentPosition(this.geolocationSuccess);
61. }
62. }
63. }
64. &amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s add the discover method to fetch address suggestions using NextBillion discover API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. methods : {
2.  // ...
3.  discover: async function () {
4.  const resp = await axios.get(`https://${import.meta.env.VITE_NEXTBILLION_API_HOST}/h/discover`, {
5.  params: {
6.  key: import.meta.env.VITE_NEXTBILLION_API_KEY,
7.  q: this.q,
8.  at: `${this.userLocation.lat},${this.userLocation.lng}`,
9.  },
10.     });
11.     this.suggestions = resp.data.items;
12.     this.showSuggestions = true;
13.     },
14.     // ...
15. }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dwL5-CsM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sp8qvneydr978til20bc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dwL5-CsM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sp8qvneydr978til20bc.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can select any suggested location to render a Marker on the Map and confirm the store or home location. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eCx_GwV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uc6s3b9m5hz05mrwuql3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eCx_GwV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uc6s3b9m5hz05mrwuql3.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Order Tracking Component
&lt;/h2&gt;

&lt;p&gt;Let us now put everything together and create an Order Tracking screen. We will use the NBaiMap component created in above section to create a live order tracking component. I am using the storeLocation and homeLocation saved to localStorage from previous step. You will want to save these loctions to your backend and fetch them to get Directions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. &amp;lt;template&amp;gt;
2. &amp;lt;div class="h-screen flex flex-col flex-1"&amp;gt;
3. &amp;lt;div class="h-full flex flex-1 flex-grow"&amp;gt;
4. &amp;lt;NBaiMap @update-path-duration="updatePathDuration" ref="nbaimap"&amp;gt;&amp;lt;/NbaiMap&amp;gt;
5. &amp;lt;/div&amp;gt;
6. &amp;lt;div class="delivery-time-container"&amp;gt;
7. &amp;lt;div class="delivery-time"&amp;gt;
8. &amp;lt;div class="delivery-duration"&amp;gt;{{ duration }}&amp;lt;/div&amp;gt;
9. &amp;lt;div class="text-sm"&amp;gt;mins&amp;lt;/div&amp;gt;
10. &amp;lt;/div&amp;gt;
11. &amp;lt;div v-if="homeAddress.address !== undefined" class="delivery-address"&amp;gt;
12. Delivering to - {{ homeAddress.address.label }}
13. &amp;lt;/div&amp;gt;
14. &amp;lt;/div&amp;gt;
15. &amp;lt;/div&amp;gt;
16. &amp;lt;/template&amp;gt;
17. &amp;lt;script lang="ts"&amp;gt;
18. import NBaiMap from "@/components/NBaiMap.vue";
19. export default {
20. name: "OrderTracking",
21. components: {
22. NBaiMap,
23. },
24. data() {
25. return {
26. duration: 0,
27. storeAddress: {},
28. homeAddress: {},
29. };
30. },
31. methods: {
32. updatePathDuration: function (duration) {
33. this.duration = Math.floor(duration / 60);
34. },
35. renderDirections: async function () {
36. this.$refs.nbaimap.renderDirections(
37. this.storeAddress.position,
38. this.homeAddress.position
39. );
40. },
41. updateLiveLocation: async function () {
42. // fetch live location from your backend
43. let liveLocationLatLng = await axios.get('backend-url');
44. this.$refs.nbaimap.updateLiveLocation(liveLocationLatLng)
45. }
46. },
47. mounted() {
48. const storeAddress = JSON.parse(localStorage.getItem("Store"));
49. const homeAddress = JSON.parse(localStorage.getItem("Home"));
50. // or fetch these locations from backend
51. if (storeAddress === null || homeAddress === null) {
52. this.$router.push({ name: "home" });
53. return;
54. }
55. this.storeAddress = storeAddress;
56. this.homeAddress = homeAddress;
57. this.renderDirections();
58. },
59. };&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Watch the demo on &lt;a href="https://youtu.be/JZg6HHoKzDo"&gt;Youtube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thats it! We can now use the OrderTracking component anywhere throughout our application for last mile delivery status.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;The full code for this example project can be found at &lt;a href="https://github.com/arjunsinghy96/nbai-order-tracking"&gt;Github Repo URL&lt;/a&gt;. Clone the project and get mapping! &lt;/p&gt;

&lt;p&gt;In our subsequent articles, we’ll be looking into optimizing delivery and delivery tracking using &lt;a href="https://doc.maps.nextbillion.io/api_reference/#tag/routing/paths/~1navigating~1json/get"&gt;NextBillion Route Optimization&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>api</category>
      <category>vue</category>
    </item>
    <item>
      <title>How to Embed Map on a Website or App Using NextBillion.ai API in 10 Minutes</title>
      <dc:creator>Nitin Yadav</dc:creator>
      <pubDate>Wed, 31 May 2023 13:27:13 +0000</pubDate>
      <link>https://dev.to/nextbillion-ai/how-to-embed-map-on-a-website-or-app-using-nextbillionai-api-in-10-minutes-3o3j</link>
      <guid>https://dev.to/nextbillion-ai/how-to-embed-map-on-a-website-or-app-using-nextbillionai-api-in-10-minutes-3o3j</guid>
      <description>&lt;p&gt;In this technical blog, we will guide you through the process of adding a map to your website or app using the NextBillion.ai API in just 10 minutes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This content was originally posted &lt;a href="https://nextbillion.ai/blog/how-to-embed-map-on-website-or-app"&gt;HERE&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will cover the necessary steps to integrate the API, including obtaining an API key, and the code snippets required to display the map on your website or app. &lt;/p&gt;

&lt;p&gt;By the end of this tutorial, you will have a fully functional map on your website or app, which you can customize to fit your needs. So, whether you’re a developer looking to embed a map feature to your project or a business owner looking to add a map to your website, this tutorial is for you. &lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to embed a map on a website step-by-step guide
&lt;/h2&gt;

&lt;p&gt;Embedding a map to a website can greatly enhance the user experience and provide valuable context for your content. One way to quickly and easily add a map to your website is by using &lt;a href="https://nextbillion.ai/"&gt;NextBillion.ai’s API&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;To add a map to your website within 10 minutes using NextBillion.ai API, you can follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nextbillion.ai/book-a-demo"&gt;Sign up&lt;/a&gt; for a trial API key on the NextBillion.ai website. This key will be used to authenticate your requests to the API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Include the NextBillion.ai API javascript library in the head of your HTML document:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;script src="https://maps-gl.nextbillion.io/maps/v2/api/js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This library provides the necessary functionality to interact with the API and display the map on your website.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a div element in your HTML document where you want the map to be displayed:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. &amp;lt;div id="map"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;strong&gt;div&lt;/strong&gt; will act as a container for the map, and its ID should be set to “map” for the initialization function to work correctly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initialize the map in your javascript:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. nb.maps.init(
2. { apiKey: 'YOUR_API_KEY', 
3.   elementId: 'map', 
4.   center: [LATITUDE, LONGITUDE], 
5.   zoom: ZOOM_LEVEL 
6. }
7. );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize the map in your javascript by calling the &lt;strong&gt;nb.maps.init()&lt;/strong&gt; function and passing in a configuration object containing your API key, the ID of the div element, and the desired center and zoom level for the map.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;strong&gt;‘YOUR_API_KEY‘&lt;/strong&gt; with your actual API key, set the center to the latitude and longitude you want the map to center on, and set the zoom level to the desired value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add some styles to the div&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. #map{ 
2.   width:100%; 
3.   height:500px; 
4. }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use CSS to style the div element and adjust the size of the map to fit your website layout. &lt;/p&gt;

&lt;p&gt;Overall, this is a simple and easy way to add a map to your website using NextBillion.ai API. With just a few lines of code, you can quickly and easily integrate a fully-functional map into your website, and customize it to suit your needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to embed a map into an app using NextBillion.ai Maps API in just ten minutes (Step-by-step Guide)
&lt;/h2&gt;

&lt;p&gt;In this section of this technical blog post, we will be discussing how to integrate a map into an app using NextBillion.ai Maps API in just ten minutes.&lt;/p&gt;

&lt;p&gt;NextBillion.ai offers a wide range of mapping services and functionalities that can be easily integrated into any app, making it a great choice for developers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Sign up for a NextBillion.ai account and log in. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Once logged in, navigate to the Maps API section and generate an API key. This key will be used to authenticate your app and allow it to access the mapping services provided by NextBillion.ai. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Import the necessary libraries for the map functionality, such as NextBillion.ai Maps SDK, into your app. These libraries provide the necessary tools and functions to implement the map functionality. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Initialize the map and set the API key in the appropriate configuration file. This will be done differently depending on the platform you are using (iOS or Android). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Add a map view to the layout of your app and connect it to the code. This is typically done through the use of XML layout files or storyboards. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: Use the map’s functions, such as moveCamera and addMarker, to customize the map according to your needs. These functions allow you to control the camera’s position, add markers and other overlays to the map, and more. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7&lt;/strong&gt;: Test the map functionality in the app by simulating or running it on a device. This will allow you to ensure that the map is working as expected and that there are no issues with the implementation. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8&lt;/strong&gt;: Integrate any additional features or customization as needed. This could include adding custom markers, creating custom overlays, or adding additional map layers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9&lt;/strong&gt;: You have successfully integrated NextBillion.ai Maps API in your app and now you can use maps in your app. &lt;/p&gt;

&lt;p&gt;In conclusion, integrating a map into an app using NextBillion.ai Maps API is a straightforward process that can be completed in just ten minutes. The platform offers a wide range of mapping services and functionalities that can be easily integrated into any app, making it a great choice for developers. Keep in mind, the above steps may vary depending on the platform and specific implementation. This is just a general guide.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to integrate a map into a Flutter app using NextBillion.ai Maps API in just ten minutes
&lt;/h2&gt;

&lt;p&gt;Integrating a map into a Flutter app can greatly enhance the user experience, allowing for location-based features such as showing nearby locations or providing directions. &lt;/p&gt;

&lt;p&gt;One option for adding a map to your app is using the NextBillion.ai Maps API. In this section of the blog post, we’ll show you how to integrate a NextBillion.ai map into your Flutter app in just ten minutes. &lt;/p&gt;

&lt;p&gt;Before getting started, you’ll need to sign up for a trial API key on the NextBillion.ai website. Once you have your API key, you can begin the integration process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Install the package
&lt;/h2&gt;

&lt;p&gt;First, you’ll need to add the nextbillion_maps package to your pubspec.yaml file. This package provides the necessary code to interact with the NextBillion.ai Maps API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. flutter pub add @nbai/nbmap-gl

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Import the package
&lt;/h2&gt;

&lt;p&gt;Next, in your Dart code, you need to import the package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. import 'package:flutter/material.dart';
2. import 'package:nbmap_gl/nbmap_gl.dart';

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Add the NextBillionMap widget
&lt;/h2&gt;

&lt;p&gt;In your app’s build method, you can add a NextBillionMap widget.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. class MyApp extends StatefulWidget {
2.   @override
3.   _MyAppState createState() =&amp;gt; _MyAppState();
4. }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It defines a Flutter widget called ‘&lt;strong&gt;MyApp&lt;/strong&gt;’ which is a ‘&lt;strong&gt;StatefulWidget&lt;/strong&gt;’. &lt;/p&gt;

&lt;p&gt;In Flutter, a &lt;strong&gt;StatefulWidget&lt;/strong&gt; is a widget that can change its state during the lifetime of the app. The &lt;strong&gt;MyApp&lt;/strong&gt; widget creates an instance of a ‘&lt;strong&gt;separate _MyAppState&lt;/strong&gt;’ class that holds the mutable state of the MyApp widget. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;@override&lt;/strong&gt; annotation before the &lt;strong&gt;createState()&lt;/strong&gt; method is a Dart feature that indicates that this method is intended to override a method with the same name that is defined in the parent class StatefulWidget. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;createState()&lt;/strong&gt; method is a factory method that returns a new instance of the _MyAppState class. This method is called by the framework when the MyApp widget is first created. &lt;/p&gt;

&lt;p&gt;In other words, this code creates a new class &lt;strong&gt;MyApp&lt;/strong&gt; that extends &lt;strong&gt;StatefulWidget&lt;/strong&gt; and is able to change its internal state, it also creates a new &lt;strong&gt;class _MyAppState&lt;/strong&gt; that holds the internal mutable state of the MyApp class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Add some styles
&lt;/h2&gt;

&lt;p&gt;Finally, you can add some styles to the map to ensure it fits well within your app’s layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
1. class _MyAppState extends State {
2.   @override
3.   Widget build(BuildContext context) {
4.     return Scaffold(
5.       body: NBMap(
6.         apiKey: 'your-api-key',
7.         initialZoom: 12,
8.         styleJson: 'https://api.nextbillion.io/maps/streets/style.json',
9.         initialPosition: LatLng(34.08572, -118.324569),
10.       ),
11.     );
12.   }
13. }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;build&lt;/strong&gt; method returns a &lt;strong&gt;Scaffold&lt;/strong&gt; widget, which is a basic layout structure in Flutter. The body property of the Scaffold widget is set to an instance of the &lt;strong&gt;NBMap&lt;/strong&gt; widget. The properties &lt;strong&gt;apiKey&lt;/strong&gt;, &lt;strong&gt;initialZoom&lt;/strong&gt;, &lt;strong&gt;styleJson&lt;/strong&gt;, and &lt;strong&gt;initialPosition&lt;/strong&gt; are passed as arguments to the NBMap widget to configure the map. &lt;/p&gt;

&lt;p&gt;The ‘Scaffold’ widget provides a basic layout structure and can be used to create a consistent layout across an app. It can also be used to provide common functionality such as a drawer, bottom sheet, and app bar. &lt;/p&gt;

&lt;p&gt;When the ‘build’ method is called, the framework uses the returned widget tree to create the elements on the screen, and it will automatically call the build method again if the state of the _MyAppState class changes. &lt;/p&gt;

&lt;p&gt;In summary, the code snippet provided defines a stateful widget in Flutter, by creating a new class MyApp that extends StatefulWidget and is able to change its internal state, it also creates a new class _MyAppState that holds the internal mutable state of the MyApp class, and uses the build method to create the user interface of the widget. &lt;/p&gt;

&lt;p&gt;Note that this is just an example and may require additional adjustments to work properly in your specific use case.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>api</category>
    </item>
  </channel>
</rss>
